我在迁移时遇到问题
Migration File
<?php
use Illuminate\Database\Schema\Blueprint;
use Illuminate\Database\Migrations\Migration;
class AlterTableMm extends Migration {
/**
* Run the migrations.
*
* @return void
*/
public function up()
{
Schema::create('downloads', function($table){
$table->engine = 'InnoDB';
$table->increments('id')->unsigned();
$table->string('title',255);
$table->string('count',45)->default(0);
$table->timestamps();
$table->integer('user_id')->unsigned();
$table->foreign('user_id')->references('id')->on('users');
});
Schema::table('marketing_materials', function($table)
{
$table->string('download_total', 45 )->default(0);
$table->integer('download_id')->unsigned();
$table->foreign('download_id')->references('id')->on('downloads');
});
}
/**
* Reverse the migrations.
*
* @return void
*/
public function down()
{
Schema::table('users', function($table)
{
$table->dropForeign('users_user_id_foreign');
});
Schema::drop('downloads');
Schema::table('marketing_materials', function($table)
{
$table->dropForeign('marketing_materials_download_id_foreign');
});
Schema::table('marketing_materials', function($table)
{
$table->dropColumn('download_total');
$table->dropColumn('download_id');
});
}
}
Error Message
[Illuminate\Database\QueryException]
SQLSTATE[23000]: Integrity constraint violation: 1452 Cannot add or update a child row: a foreign key constraint fails (`distributor-local`.`#sql-668_3d`, CONSTRAINT `marketing_mater
ials_download_id_foreign` FOREIGN KEY (`download_id`) REFERENCES `downloads` (`id`)) (SQL: alter table `marketing_materials` add constraint marketing_materials_download_id_foreign fo
reign key (`download_id`) references `downloads` (`id`))
[PDOException]
SQLSTATE[23000]: Integrity constraint violation: 1452 Cannot add or update a child row: a foreign key constraint fails (`distributor-local`.`#sql-668_3d`, CONSTRAINT `marketing_mater
ials_download_id_foreign` FOREIGN KEY (`download_id`) REFERENCES `downloads` (`id`))
我有所有必需的表格
有人可以告诉我,我做错了什么吗?
让我误解了大部分错误信息的部分是,所有内容都被添加到数据库中。见下图
我也改变了我的marketing_materials表,这也是有效的。
我应该忽略错误信息???