小编Mar*_*spi的帖子

MySQL 创建表:错误 1005 errno: 150 “外键约束格式不正确”

为什么 laravel schema 回复:

SQLSTATE[HY000]:一般错误:1005 无法创建表 employee_managementemployees(errno: 150 "外键约束格式不正确") (SQL: alter tableemployees添加约束 employees_city_id_foreign外键 ( city_id) 引用city ( id))

PDOException::("SQLSTATE[HY000]: 一般错误: 1005 无法创建表employee_managementemployees(errno: 150 "外键约束格式不正确")")

我的桌子:

  Schema::create('employees', function (Blueprint $table) {
            $table->increments('id', true);
            $table->string('lastname', 60);
            $table->string('firstname', 60);
            $table->string('middlename', 60);
            $table->string('address', 120);
            $table->integer('city_id')->unsigned();
            $table->integer('state_id')->unsigned();
            $table->integer('country_id')->unsigned();;
            $table->foreign('city_id')->references('id')->on('city');
            $table->foreign('state_id')->references('id')->on('state');
            $table->foreign('country_id')->references('id')->on('country');
            $table->char('zip', 10);
            $table->integer('age')->unsigned();
            $table->date('birthdate');
            $table->date('date_hired');
            $table->integer('department_id')->unsigned();
            $table->integer('division_id')->unsigned();
            // $table->integer('company_id')->unsigned();
            $table->foreign('department_id')->references('id')->on('department');
            $table->foreign('division_id')->references('id')->on('division');
            // $table->foreign('company_id')->references('id')->on('company');
            $table->string('picture', 60);
            $table->timestamps();
            $table->softDeletes();
        });
Run Code Online (Sandbox Code Playgroud)

我的第二张城市表:

Schema::create('city', function …
Run Code Online (Sandbox Code Playgroud)

mysql laravel

3
推荐指数
1
解决办法
5271
查看次数

标签 统计

laravel ×1

mysql ×1