Skip to content

Can't run migration without foreign key error #63

@newscloud

Description

@newscloud

What steps will reproduce the problem?

codeception/bin/yii migrate
Yii Migration Tool (based on Yii v2.0.8)

Creating migration history table "migration"...Done.
Total 7 new migrations to be applied:
m141201_013120_create_status_table
m150128_003709_extend_status_table_for_created_by
m150128_233458_extend_status_table_for_slugs
m150209_200619_extend_status_table_for_updated_by
m150209_204852_create_status_log_table
m150219_235923_create_sample_table
m160316_201654_extend_status_table_for_image

Apply the above migrations? (yes|no) [no]:yes
*** applying m141201_013120_create_status_table
> create table {{%status}} ... done (time: 0.006s)
*** applied m141201_013120_create_status_table (time: 0.023s)

*** applying m150128_003709_extend_status_table_for_created_by
> add column created_by integer NOT NULL to table {{%status}} ... done (time: 0.008s)
> add foreign key fk_status_created_by: {{%status}} (created_by) references {{%user}} (id) ...Exception 'yii\db\Exception' with message 'SQLSTATE[HY000]: General error: 1005 Can't create table 'yii2_basic_tests.#sql-98f_22' (errno: 150)
The SQL being executed was: ALTER TABLE status ADD CONSTRAINT fk_status_created_by FOREIGN KEY (created_by) REFERENCES user (id) ON DELETE CASCADE ON UPDATE CASCADE'

What's expected?

Completed migration

What do you get instead?

error above

Additional info

Adding foreign keys for the test fails.

I did a composer self-update and composer-update before re-testing. The db permissions do work, status table is created okay.

Also codeception is installed properly.

Q A
Yii vesion
PHP version
Operating system

Metadata

Metadata

Assignees

Labels

Type

No type

Projects

No projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions