I'm trying to populate a database using seeder.
I get an error:
SQLSTATE[23000]: Integrity constraint violation: 1451 Cannot delete or update a parent row: a foreign key constraint fails (forge.projects, CONSTRAINT projects_status_id_foreign FOREIGN KEY (status_id) REFERENCES status_projects (id))
Here are my migrations:
public function up()
{
Schema::create('projects', function (Blueprint $table) {
$table->increments('id');
$table->string('name');
$table->string('subtitle');
$table->longText('main_data');
$table->string('budget_description');
$table->integer('owner_id')->unsigned();
$table->integer('category_id')->unsigned();
$table->integer('deadline_id')->unsigned();
$table->integer('city_id')->unsigned();
$table->string('website')->nullable()->default('null'); //reference
$table->decimal('budget', 18, 4);
$table->integer('status_id')->unsigned()->default('1');
$table->dateTime('started_at')->nullable();
$table->integer('account_id')->unsigned()->default(1);
$table->timestamps();
$table->softDeletes();
});
}
This is a migration for Status:
public function up()
{
Schema::create('status_projects', function (Blueprint $table) {
$table->increments('id');
$table->string('name');
});
}
Several people are working on this project, so I created an additional migration:
public function up()
{
Schema::table('projects', function (Blueprint $table) {
$table->unsignedInteger('status_id');
$table->foreign('status_id')
->references('id')->on('status_projects')
->onDelete('cascade');
});
}
Now when I try to execute the command
php artisan migrate
I get error:
SQLSTATE[42S21]: Column already exists: 1060 Duplicate column name 'status_id' (SQL: alter table projects add status_id int unsigned null)
How can I fix this?
JavaScript questions and answers, JavaScript questions pdf, JavaScript question bank, JavaScript questions and answers pdf, mcq on JavaScript pdf, JavaScript questions and solutions, JavaScript mcq Test , Interview JavaScript questions, JavaScript Questions for Interview, JavaScript MCQ (Multiple Choice Questions)