早上好,
我无法将数据从我的工厂发送到我的数据库。
SQLSTATE[HY000]: General error: 1364 Field 'genre_id' doesn't have a default value (SQL: insert into `books` (`isbn`, `title`, `publish_date`, `updated_at`, `created_at`) values (4243421897, Prof., 1992-09-08 00:57:41, 2020-03-10 15:02:36, 2020-03-10 15:02:36))
我不知道在我的迁移中是否必须指定我的 foreign_keys 没有默认值......
这些是我的文件:
create_books_table.php
public function up()
{
Schema::create('books', function (Blueprint $table) {
$table->engine = 'InnoDB';
$table->id('isbn');
$table->string('title' , 100);
$table->text('cover')->nullable();
$table->date('publish_date');
$table->bigInteger('genre_id')->unsigned();
$table->bigInteger('author_id')->unsigned();
$table->bigInteger('user_id')->unsigned();
$table->timestamps();
$table->foreign('genre_id')
->references('id')->on('Genres')
->onUpdate('cascade')
->onDelete('cascade');
$table->foreign('author_id')
->references('id')->on('Authors')
->onUpdate('cascade')
->onDelete('cascade');
$table->foreign('user_id')
->references('id')->on('Readers')
->onUpdate('cascade')
->onDelete('cascade');
});
}
BookFactory.php
$factory->define(Book::class, function (Faker $faker) {
return [
'isbn' => $faker->isbn10,
'title' => $faker->title,
'publish_date' => $faker->dateTime()
];
});
我还没有在我的 web.php 中创建一个“路由”,所以我也没有完成 CRUD,我什至没有修改我的刀片,但我现在只想设置我的整个数据库。但我想知道这是否不是问题所在。
这是我数据库中的示意图: https ://imgur.com/a/8Txn7x2 (我还不允许上传图片。)
(我在编码学校)
谢谢!