我知道这个问题已经问了很多次了,但是我尝试了每一个解决方案,但它仍然给了我一个错误。
我想迁移我的桌子:
class CreateFichesTable extends Migration
{
public function up()
{
Schema::create('fiches', function (Blueprint $table) {
$table->engine = 'InnoDB';
$table->increments('id');
$table->string('type');
$table->string('nom');
$table->string('description');
$table->string('image');
$table->integer('equipe_id')->unsigned();
$table->timestamps();
});
Schema::table('fiches', function(Blueprint $table)
{
$table->foreign('equipe_id')->references('id')->on('equipes');
});
}}
和
class CreateEquipesTable extends Migration
{
public function up()
{
Schema::create('equipes', function (Blueprint $table) {;
$table->increments('id');
$table->string('nom');
$table->string('image');
$table->timestamps();
});
}}
我得到了:
Exception trace:
1 PDOException::("SQLSTATE[HY000]: General error: 1215 Cannot add foreign
key constraint")我试图强制使用引擎"InnoDB“,但仍然无法工作。
有小费吗?
发布于 2018-09-03 15:36:15
当您创建新的迁移文件时,laravel会自动添加到开始日期时间中,比如这个2018_08_10_111004_,用于检测必须首先创建哪个迁移。正如您在注释中显示的,您的迁移文件是2018_08_31_141536_create_fiches_table.php和2018_09_03_141649_create_equipes_table.php,您必须将其中一个迁移更改为首先称为第二个迁移,第一个迁移。
例如
2018_08_31_141536_create_fiches_table.php
2018_08_30_141649_create_equipes_table.phphttps://stackoverflow.com/questions/52152309
复制相似问题