我使用 Laravel5.4 构建 Twitter 克隆应用程序并参考此
现在我想要用测试数据播种数据库
在我的终端输入中php artisan db:seed --class=TweetsTableSeeder
出现错误
Integrity constraint violation: 1452 Cannot add
or update a child row: a foreign key constraint fails (`twitter`.
`tweets`, CONSTRAINT `tweets_user_id_foreign` FOREIGN KEY (`user_
id`) REFERENCES `users` (`id`) ON DELETE CASCADE)
Run Code Online (Sandbox Code Playgroud)
我阅读了错误并尝试理解,但没有得到好的结果。我正在看官方文档,但由于初学者,我不太明白。
所以请帮助我
2017_07_09_create_tweets_table
<?php
use Illuminate\Support\Facades\Schema;
use Illuminate\Database\Schema\Blueprint;
use Illuminate\Database\Migrations\Migration;
class CreateTweetsTable extends Migration
{
/**
* Run the migrations.
*
* @return void
*/
public function up()
{
Schema::create('tweets', function (Blueprint $table) {
$table->increments('id');
$table->integer('user_id')->unsigned()->index();
$table->foreign('user_id')->references('id')->on('users')->onDelete('cascade'); …Run Code Online (Sandbox Code Playgroud)