小编m4r*_*ii0的帖子

一般错误:1215 无法在 Laravel 中添加外键约束

做迁移我得到这个错误: SQLSTATE[HY000]: General error: 1215 Cannot add foreign key constraint (SQL: alter table booksadd constraint books_writer_id_foreignforeign key ( writer_id) references writers( id)) 我已经尝试了很多事情,但没有人看起来工作.

2018_02_18_3165165_create_books_table.php

<?php

use Illuminate\Support\Facades\Schema;
use Illuminate\Database\Schema\Blueprint;
use Illuminate\Database\Migrations\Migration;

class CreateBooksTable extends Migration
{
    /**
     * Run the migrations.
     *
     * @return void
     */
    public function up()
    {
        Schema::create('books', function (Blueprint $table) {
            $table->engine = 'InnoDB';

            $table->increments('id');


            $table->string('name');
            $table->text('description');

            $table->integer('numPages');
            $table->enum('language', ['spanish', 'english']);

            $table->date('wrote_date')->nullable();


            $table->timestamp('created_at')->useCurrent();
            $table->timestamp('updated_at')->default(DB::raw('CURRENT_TIMESTAMP ON UPDATE CURRENT_TIMESTAMP'));
        });
        Schema::table('books', function (Blueprint …
Run Code Online (Sandbox Code Playgroud)

php mysql migration laravel

3
推荐指数
2
解决办法
9948
查看次数

标签 统计

laravel ×1

migration ×1

mysql ×1

php ×1