我使用laravel迁移一些数据,但我有下面这条消息:Laravel 5.1 - 常规错误:1005无法创建表(MySQL的)
[Illuminate\Database\QueryException]
SQLSTATE[HY000]: General error: 1005 Can't create table 'heinz.#sql-1e83_8' (errno: 150) (SQL: alter table `funcionarios` add constraint funcionarios_supervisor_id_foreign foreign key (`supervis
or_id`) references `funcionarios` (`id`))
我尝试了很多东西,但没有工作。
这是迁移文件的代码。 (相关部分)。
Schema::create('funcionarios', function (Blueprint $table) {
// $table->engine = 'InnoDB';
$table->increments('id');
$table->string('nome', 60);
$table->integer('matricula')->unsigned()->unique();
$table->bigInteger('pis_pasep')->unsigned()->nullable();
$table->date('data_admissao')->nullable();
$table->date('data_demissao')->nullable()->default(null);
$table->date('data_nascimento')->nullable();
$table->string('apelido', 20)->nullable();
$table->integer('supervisor_id')->nullable();
$table->integer('coordenador_id')->nullable();
$table->integer('gerente_id')->nullable();
$table->integer('diretor_id')->nullable();
$table->integer('sexo_id')->nullable();
$table->integer('setor_id')->nullable();
$table->integer('cargo_id');
$table->integer('turno_id')->nullable();
$table->timestamps();
});
Schema::table('funcionarios', function($table){
$table->foreign('supervisor_id')->references('id')->on('funcionarios');
$table->foreign('coordenador_id')->references('id')->on('funcionarios');
$table->foreign('gerente_id')->references('id')->on('funcionarios');
$table->foreign('diretor_id')->references('id')->on('funcionarios');
$table->foreign('sexo_id')->references('id')->on('sexos');
$table->foreign('setor_id')->references('id')->on('setores');
$table->foreign('cargo_id')->references('id')->on('cargos');
$table->foreign('turno_id')->references('id')->on('turnos');
});
此处同样的错误。 –
不用等。我只是忘了一个键来做无符号的。有效! –
Amarnasan,你怎么知道外表中的密钥是未签名的? – silkfire