这是我的代码架构goimon
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`))