Laravel 6.5.1 迁移错误号:语法错误或访问冲突 1064
Laravel 6.5.1 migration Errno: Syntax error or access violation 1064
我尝试进行迁移,但 运行 遇到此错误:语法错误或访问冲突 1064。我查看了其他类似问题,但找不到解决此问题的方法。请帮助,并提前致谢。
Schema::create('posts', function (Blueprint $table) {
$table->bigIncrements('id');
$table->unsignedBigInteger('author_id');
$table->foreign('author_id')->references('id')->on('authors')->onDelete('cascade');
$table->string('title');
$table->text('excerpt');
$table->longText('body');
$table->binary('post_image');
$table->timestamp('published_at')->nullable();
$table->timestamps();
$table->softDeletes();
});
Schema::create('authors', function (Blueprint $table) {
$table->bigIncrements('id');
$table->string('fist_name');
$table->string('last_name');
$table->binary('pic')->nullable();
$table->timestamps();
$table->softDeletes();
});
假设这是创建两个 table 的单个迁移。在我看来,这不是最好的主意。最好将每个 table 分成自己的迁移。
尝试切换两个创建块。因此,在 posts
-table 完成之前,authors
-table 已经创建。
因为您试图将 posts
-table 中的外键设置为尚未创建 authors
-table 但它们都必须存在。
我也倾向于将外键约束与 table 的实际结构分开,以便更好地了解。但这是个人意见。
Schema::create('authors', function (Blueprint $table) {
$table->bigIncrements('id');
$table->string('fist_name');
$table->string('last_name');
$table->binary('pic')->nullable();
$table->timestamps();
$table->softDeletes();
});
Schema::create('posts', function (Blueprint $table) {
$table->bigIncrements('id');
$table->unsignedBigInteger('author_id');
$table->string('title');
$table->text('excerpt');
$table->longText('body');
$table->binary('post_image');
$table->timestamp('published_at')->nullable();
$table->timestamps();
$table->softDeletes();
$table->foreign('author_id')->references('id')->on('authors')->onDelete('cascade');
});
希望对您有所帮助。
我尝试进行迁移,但 运行 遇到此错误:语法错误或访问冲突 1064。我查看了其他类似问题,但找不到解决此问题的方法。请帮助,并提前致谢。
Schema::create('posts', function (Blueprint $table) {
$table->bigIncrements('id');
$table->unsignedBigInteger('author_id');
$table->foreign('author_id')->references('id')->on('authors')->onDelete('cascade');
$table->string('title');
$table->text('excerpt');
$table->longText('body');
$table->binary('post_image');
$table->timestamp('published_at')->nullable();
$table->timestamps();
$table->softDeletes();
});
Schema::create('authors', function (Blueprint $table) {
$table->bigIncrements('id');
$table->string('fist_name');
$table->string('last_name');
$table->binary('pic')->nullable();
$table->timestamps();
$table->softDeletes();
});
假设这是创建两个 table 的单个迁移。在我看来,这不是最好的主意。最好将每个 table 分成自己的迁移。
尝试切换两个创建块。因此,在 posts
-table 完成之前,authors
-table 已经创建。
因为您试图将 posts
-table 中的外键设置为尚未创建 authors
-table 但它们都必须存在。
我也倾向于将外键约束与 table 的实际结构分开,以便更好地了解。但这是个人意见。
Schema::create('authors', function (Blueprint $table) {
$table->bigIncrements('id');
$table->string('fist_name');
$table->string('last_name');
$table->binary('pic')->nullable();
$table->timestamps();
$table->softDeletes();
});
Schema::create('posts', function (Blueprint $table) {
$table->bigIncrements('id');
$table->unsignedBigInteger('author_id');
$table->string('title');
$table->text('excerpt');
$table->longText('body');
$table->binary('post_image');
$table->timestamp('published_at')->nullable();
$table->timestamps();
$table->softDeletes();
$table->foreign('author_id')->references('id')->on('authors')->onDelete('cascade');
});
希望对您有所帮助。