Laravel 5 errno150无法创建表迁移
这是我的代码模式Laravel 5 errno150无法创建表迁移,laravel-5,Laravel 5,这是我的代码模式 public function up() { Schema::create('goimon', function (Blueprint $table) { $table->engine = 'InnoDB'; $table->charset = 'utf8'; $table->collation = 'utf8_unicode_ci'; $t
public function up()
{
Schema::create('goimon', function (Blueprint $table) {
$table->engine = 'InnoDB';
$table->charset = 'utf8';
$table->collation = 'utf8_unicode_ci';
$table->increments('MaGoiMon');
$table->string('TinhTrang');
//$table->unsignedInteger('MaNhanVien');
$table->integer('MaNhanVien')->unsigned();
$table->unsignedInteger('MaBan');
$table->foreign('MaBan')->references('MaBan')->on('banan');
$table->foreign('MaNhanVien')->references('MaNhanVien')->on('nhanvien');
$table->timestamps();
});
}
第二种模式:
public function up()
{
Schema::create('nhanvien', function (Blueprint $table) {
$table->engine = 'InnoDB';
$table->increments('MaNhanVien');
$table->string('TenNhanVien');
$table->string('TenDangNhap');
$table->string('MatKhau');
$table->boolean('GioiTinh');
$table->date('NgaySinh');
$table->integer('CMND');
$table->integer('quyen');
$table->timestamps();
});
}
还有我的错误
Illuminate\Database\QueryException : SQLSTATE[HY000]: General error:
1005 Can't create table `qlnhahang`.`#sql-12bc_
491` (errno: 150 "Foreign key constraint is incorrectly formed") (SQL:
alter table `goimon` add constraint `goimon_manhanvien_foreign`
foreign key (`MaNhanVien`) references `nhanvien` (`MaNhanVien`))
请明确说明您的问题以及解决问题的任何尝试=)您是在
goimon
之前还是之后创建nhanvien
表的?