我正在使用 laravel 的 artisan 命令创建带有外键的数据库表。当我运行 php artisan migrate
命令时,出现以下错误:
SQLSTATE[23000]: Integrity constraint violation: 1022 Can't write; duplicate key in table '#sql-73_ca' (SQL: alter table
table_1
add constrainttable_1_table_1_sid_foreign
foreign key
(table_1_sid
) referencestable_2
(id
))
此外,我没有表“#sql-73_ca”
最佳答案
如果您使用phpmyadmin,您应该将错误通知的一部分复制到phpmyadmin中的查询sql中:
" alter table table_1 add constraint table_1_table_1_sid_foreign
foreign key (table_1_sid) references table_2 (id)"
它将显示更多错误信息
关于php - 使用外键创建表时 Laravel 迁移错误,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/48092975/