【发布时间】:2019-12-22 21:15:52
【问题描述】:
我有以下表架构;
Schema::create('users', function (Blueprint $table) {
$table->bigIncrements('id');
$table->string('name');
$table->string('email');
$table->timestamp('email_verified_at')->nullable();
$table->string('password');
$table->string('account_type')->default('1,1,0');
$table->string('theme')->default('light');
$table->string('unique_id')->nullable();
$table->string('avatar')->nullable();
$table->rememberToken();
$table->timestamps();
$table->unsignedBigInteger('plan_id');
$table->foreign('plan_id')->references('id')->on('plans');
$table->unique('email');
});
当我运行迁移时,它失败并出现错误:
errno: 150 "外键约束格式不正确"
如果我删除了外键,它仍然不起作用。
如果我将表名从“用户”更改为其他任何名称,它确实有效,但如果我再次运行它会失败(需要再次更改表名)。
这是引用表的架构,此迁移也在用户迁移之前运行。
Schema::create('plans', function (Blueprint $table) {
$table->bigIncrements('id');
$table->string('name')->unique();
$table->float('cost', 8, 2)->nullable();
$table->integer('free_trial');
$table->string('renewal_rate');
$table->string('features');
$table->string('stripe_plan');
$table->boolean('featured')->default(true);
$table->string('permission');
$table->timestamps();
});
花了几天时间试图解决这个问题,每个人似乎都指出bigIncrements/unsignedBigIncrements 与列名中的拼写错误相同。我好像没有这个问题。。
【问题讨论】:
-
所以如果你使用“asdasdasd”之类的用户而不是它,它可以工作吗?
-
users 将无法工作,如果我更改表名一次,它会工作,但它会再次中断,并出现上述错误。我希望表名是用户。
标签: mysql sql laravel laravel-5.8