【发布时间】:2021-09-23 16:47:58
【问题描述】:
我想从表“users”中用de外键“users_id”创建de表“livros”,但我无法迁移。
表格:
public function up()
{
Schema::create('livros', function (Blueprint $table) {
$table->id();
$table->integer('users_id');
$table->foreign('users_id')->references('id')->on('users');
/*Auth::user()->id;*/
$table->text('namel');
$table->string('autor');
$table->string('editora');
$table->string('categoria');
$table->string('classificação');
$table->text('descricao');
$table->string('image')->nullable();
$table->timestamp('created_at')->nullable();
$table->timestamp('updated_at')->nullable();
});
}
【问题讨论】:
-
把这个改成
$table->unsignedBigInteger('users_id'); -
livros 上的 users_id 和 users 上的 id 的列定义必须匹配。默认情况下,在 Laravel 8 中,主键的列定义是 unsignedBigInteger,因此将其用于 users_id。
-
请向我们展示用户表迁移
标签: php mysql laravel laravel-8