【发布时间】:2020-11-27 03:51:34
【问题描述】:
Schema::create('projects', function (Blueprint $table) {
$table->id();
$table->string('name');
$table->timestamps();
});
Schema::create('users', function (Blueprint $table) {
$table->id();
$table->foreignId('project_id')->constrained();
$table->string('name');
$table->string('email')->unique();
$table->timestamp('email_verified_at')->nullable();
$table->string('password');
$table->rememberToken();
$table->timestamps();
});
Schema::create('tasks', function (Blueprint $table) {
$table->id();
$table->foreignId('user_id')->constrained();
$table->string('name');
$table->timestamps();
});
当我运行 php artisan migrate 时,仅创建 users 表,然后迁移过程停止...
SQLSTATE[HY000]:一般错误:1005 无法创建表
Projectname.users(errno: 150 "外键约束为 格式不正确”)(SQL:alter tableusers添加约束users_project_id_foreign外键 (project_id) 引用projects(id))
【问题讨论】:
-
将帮助我查看实际的 SQL。否则取决于 laravel 的人。
-
我给了你一个带有描述的答案,如果有帮助,那么将该答案标记为已接受
标签: php mysql laravel laravel-7 laravel-migrations