php - 如何: migration many-to-many laravel artisan

标签 php laravel migration many-to-many laravel-artisan

我正在尝试找到一种方法来迁移(以及后来的种子)由 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/

相关文章:

laravel - 身份验证器 "LOGIN"返回 "Expected response code "23 5"but got code "53 5", with message "535 身份验证失败“。”

mysql - 飞行 route 连接超时

php - PHP 文档的 REQUEST_URI 是 "favicon.ico"或样式表的文件名

php - MYSQL 查询返回“资源 id#12”而不是它应返回的数值

php - 测验表字段的索引基数是 '2' ,但应该是 '0'

php - 拉维尔 4 : Where Not Exists

php - 为人对人禁用 Laravel 复数

javascript - .menu() 不是函数; jQuery升级

php - Laravel:如何在迁移中运行控制台命令?

php - mysql什么会更快