我正在尝试找到一种方法来迁移(以及后来的种子)由 laravel 5.2 中的多对多关系生成的表(使用 artisan)。
我这里有 User.php 和 Role.php 模型。我还尝试了多对多表的迁移。 I can't work well with codeblocks here, so this is my code.
我收到错误:
General error: 1005 Can't create table 'connect.#sql-2d0_2e' (errno: 150) (SQL: alter table 'users_has_roles' add constraint users_has_roles_usersid_foreign foreign key ('usersId') references 'users' ('id'))
最佳答案
问题可能是:
$table->bigInteger('usersId')->unsigned();
如果您查看users
表,id
的列类型是什么。我认为它是整数(无符号),因此它必须与您为其创建外键的列完全相同,因此您可能应该将上面更改为:
$table->integer('usersId')->unsigned();
关于php - 如何: migration many-to-many laravel artisan,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/34441698/