Closed PhilippHandle closed 4 years ago
Could you provide SHOW CREATE TABLE
output?
Do you mean something like that? Table before migrations:
-- auto-generated definition
create table task_jobs
(
id int(20) auto_increment
)
charset = utf8mb4;
alter table task_jobs
add primary key (id);
Table after migration
-- auto-generated definition
create table task_jobs
(
id int(20) auto_increment,
task_id int(20) null,
run_at datetime not null,
status int(1) default 0 null,
result text null,
constraint task_jobs_id_uindex
unique (id),
constraint task_jobs_tasks_id_fk
foreign key (task_id) references tasks (id)
on delete set null
)
charset = utf8mb4;
alter table task_jobs
add primary key (id);
Is table tasks
already created?
yes in the first run i create every table with the primary key and in the second run i add all other fields and relations
Fixed.
Currently i'm upgrading to devtools 4.0.0 and running in some strange issues. Migrations are running fine with the old version
I have 2 migrations for the a table: 0.0.1 create table
$this->getConnection()->createTable( 'task_jobs', '', [ 'columns' => [ new Column( 'id', [ 'type' => Column::TYPE_INTEGER, 'size' => 20, 'notNull' => true, 'autoIncrement' => true, ] ), ], 'indexes' => [ new Index( 'PRIMARY', [ 'id' ], 'PRIMARY' ) ], 'options' => [ 'TABLE_TYPE' => 'BASE TABLE', 'AUTO_INCREMENT' => '1', 'ENGINE' => 'InnoDB', 'TABLE_COLLATION' => 'utf8mb4_general_ci' ], ] );
Second 0.1.0 creates the rest
$this->morphTable( 'task_jobs', [ 'columns' => [ new Column( 'id', [ 'type' => Column::TYPE_INTEGER, 'notNull' => true, 'autoIncrement' => true, 'size' => 20, 'first' => true ] ), new Column( 'task_id', [ 'type' => Column::TYPE_INTEGER, 'size' => 20, 'after' => 'id' ] ), new Column( 'run_at', [ 'type' => Column::TYPE_DATETIME, 'notNull' => true, 'size' => 1, 'after' => 'task_id' ] ), new Column( 'status', [ 'type' => Column::TYPE_INTEGER, 'default' => "0", 'size' => 1, 'after' => 'run_at' ] ), new Column( 'result', [ 'type' => Column::TYPE_TEXT, 'size' => 1, 'after' => 'status' ] ) ], 'indexes' => [ new Index( 'PRIMARY', [ 'id' ], 'PRIMARY' ), new Index( 'task_jobs_id_uindex', [ 'id' ], 'UNIQUE' ), new Index( 'task_jobs_tasks_id_fk', [ 'task_id' ], '' ) ], 'references' => [ new Reference( 'task_jobs_tasks_id_fk', [ 'referencedTable' => 'tasks', 'referencedSchema' => '', 'columns' => [ 'task_id' ], 'referencedColumns' => [ 'id' ], 'onUpdate' => 'RESTRICT', 'onDelete' => 'SET NULL' ] ) ], 'options' => [ 'TABLE_TYPE' => 'BASE TABLE', 'AUTO_INCREMENT' => '103706', 'ENGINE' => 'InnoDB', 'TABLE_COLLATION' => 'utf8mb4_general_ci' ], ] );
But now i get the error:
PHP Fatal error: Uncaught TypeError: Argument 2 passed to Phalcon\Db\Adapter\Pdo\Mysql::addForeignKey() must be of the type string, null given in /var/www/xxx/public_html/vendor/phalcon/migrations/src/Mvc/Model/Migration.php:728
if i change
$tableReference->getSchemaName()
to$tableReference->getSchemaName() ?? ''
it works fine.What do i need to set/enable what ever to fix that?