【发布时间】:2013-12-30 05:03:21
【问题描述】:
尝试在 Laravel 中添加外键约束时,出现以下错误。
[PDOException]
SQLSTATE[HY000]: General error: 1005 Can't create table 'ts.#sql-5769_62' (errno: 150)
我有 2 张桌子,users 和 teams。关系是团队可以有许多用户,而用户有一个团队。
用户
$table->increments('id');
$table->integer('team_id');
$table->string('name', 255);
$table->string('username', 32)->unique();
$table->string('email', 320);
$table->string('password', 64);
$table->foreign('team_id')->references('id')->on('teams');
$table->timestamps();
团队
$table->increments('id');
$table->string('team_name', 255);
$table->string('website', 255);
$table->timestamps();
我做错了什么?这也是我第一次使用迁移,所以欢迎任何帮助指出愚蠢的错误。
【问题讨论】:
-
“尝试添加外键约束时”---你是怎么做的?
-
抱歉我没关注?
-
看来为什么不行。
标签: php mysql laravel laravel-4