dns_project dns_project - 1 month ago 10
MySQL Question

Phinx transaction doesn't work

Trying to figure out how transaction works at phinx package. Here is my migration code and it doesn't work. I use

mysql
and everything is ok with
phinx.yml
. So table
acme
is created while table
fail
fails and no records are found in
phinxlog
table. So, when I ran
phinx migrate
I've error
SQLSTATE[42S01]: Base table or view already exists: 1050 Table 'acme' already exists
. So, how can I use transactions? I didn't find any docs about it, Help me please))

public function up()
{
$this->getAdapter()->beginTransaction();
$this->table('acme')->addColumn('name', 'string')->create();
$this->table('fail')->addColumn('lal', 'failme')->create();
$this->getAdapter()->commitTransaction();
}

Answer

Transactions only apply to data (DML) changes with mysql. You cannot 'transact' data definition changes (DDL).

http://dev.mysql.com/doc/refman/5.7/en/cannot-roll-back.html

But other DBs can (under certain conditions).

Is it possible to roll back CREATE TABLE and ALTER TABLE statements in major SQL databases?