Laravel:How to fix SQLSTATE[23000]: Integrity constraint violation?Laravel Migration foreign key errorGeneral error: 1005 Can't create tableForeign key constraint fails on nullable fieldSQLSTATE[23000]: Integrity constraint violation: 1452 Cannot add or update a child row: a foreign key constraint failsLaravel Delete function not workUsing UUID as primary key on users table causes PDOEXCEPTION errorFrom campaign table i want to delete campaign but i can't delete..following error occurLaravel: SQLSTATE[23000]: Integrity constraint violation: 1452 Cannot add or update a child row: a foreign key constraint failsGet results from pivot table based on the combination of two IDs in Laravel ProjectLaravel Migration : Errcode: 150 “Foreign key constraint is incorrectly formed”

Why would a car salesman tell me not to get my credit pulled again?

How can powerful telekinesis avoid violating Newton's 3rd Law?

How can I find out about the game world without meta-influencing it?

If absolute velocity does not exist, how can we say a rocket accelerates in empty space?

As easy as Three, Two, One... How fast can you go from Five to Four?

Can I attach a DC blower to intake manifold of my 150CC Yamaha FZS FI engine?

How to properly use a function under a class?

Why would a home insurer offer a discount based on credit score?

David slept with Bathsheba because she was pure?? What does that mean?

Is it true that "only photographers care about noise"?

Is it possible to have battery technology that can't be duplicated?

Are skill challenges an official option or homebrewed?

Why did Robert pick unworthy men for the White Cloaks?

Why is it bad to use your whole foot in rock climbing

Is it a good security practice to force employees hide their employer to avoid being targeted?

Is this Homebrew Eldritch Invocation, Accursed Memory, balanced?

When to use the uncountable form of a noun?

Oxford comma with nonessential phrases

Must CPU have a GPU if motherboard provides display port (when no separate video card)?

In American Politics, why is the Justice Department under the President?

Which game is this?

Am I allowed to determine tenets of my contract as a warlock?

Nth term of Van Eck Sequence

What class is best to play when a level behind the rest of the party?



Laravel:How to fix SQLSTATE[23000]: Integrity constraint violation?


Laravel Migration foreign key errorGeneral error: 1005 Can't create tableForeign key constraint fails on nullable fieldSQLSTATE[23000]: Integrity constraint violation: 1452 Cannot add or update a child row: a foreign key constraint failsLaravel Delete function not workUsing UUID as primary key on users table causes PDOEXCEPTION errorFrom campaign table i want to delete campaign but i can't delete..following error occurLaravel: SQLSTATE[23000]: Integrity constraint violation: 1452 Cannot add or update a child row: a foreign key constraint failsGet results from pivot table based on the combination of two IDs in Laravel ProjectLaravel Migration : Errcode: 150 “Foreign key constraint is incorrectly formed”






.everyoneloves__top-leaderboard:empty,.everyoneloves__mid-leaderboard:empty,.everyoneloves__bot-mid-leaderboard:empty height:90px;width:728px;box-sizing:border-box;








0















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?










share|improve this question
























  • Because when trying migrating, you have the same column in both (separate) migrations -$table->unsignedInteger('status_id'); and $table->integer('status_id')->unsigned()->default('1');. Delete it in your additional migration and php artisan migrate:refresh.

    – senty
    Mar 25 at 1:32


















0















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?










share|improve this question
























  • Because when trying migrating, you have the same column in both (separate) migrations -$table->unsignedInteger('status_id'); and $table->integer('status_id')->unsigned()->default('1');. Delete it in your additional migration and php artisan migrate:refresh.

    – senty
    Mar 25 at 1:32














0












0








0








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?










share|improve this question
















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?







database laravel migration






share|improve this question















share|improve this question













share|improve this question




share|improve this question








edited Mar 25 at 4:26









Udhav Sarvaiya

2,81392132




2,81392132










asked Mar 24 at 23:32









YuliiaYuliia

95




95












  • Because when trying migrating, you have the same column in both (separate) migrations -$table->unsignedInteger('status_id'); and $table->integer('status_id')->unsigned()->default('1');. Delete it in your additional migration and php artisan migrate:refresh.

    – senty
    Mar 25 at 1:32


















  • Because when trying migrating, you have the same column in both (separate) migrations -$table->unsignedInteger('status_id'); and $table->integer('status_id')->unsigned()->default('1');. Delete it in your additional migration and php artisan migrate:refresh.

    – senty
    Mar 25 at 1:32

















Because when trying migrating, you have the same column in both (separate) migrations -$table->unsignedInteger('status_id'); and $table->integer('status_id')->unsigned()->default('1');. Delete it in your additional migration and php artisan migrate:refresh.

– senty
Mar 25 at 1:32






Because when trying migrating, you have the same column in both (separate) migrations -$table->unsignedInteger('status_id'); and $table->integer('status_id')->unsigned()->default('1');. Delete it in your additional migration and php artisan migrate:refresh.

– senty
Mar 25 at 1:32













1 Answer
1






active

oldest

votes


















0














This should solve the problem: you have to refresh your database (ps: you are going to re-insert your rows)



php artisan migrate refresh 





share|improve this answer

























  • Unfortunately, this solution does not work for me.

    – Yuliia
    Mar 25 at 0:22











  • I don't understand, how can I avoid re-adding?

    – Yuliia
    Mar 25 at 0:24











Your Answer






StackExchange.ifUsing("editor", function ()
StackExchange.using("externalEditor", function ()
StackExchange.using("snippets", function ()
StackExchange.snippets.init();
);
);
, "code-snippets");

StackExchange.ready(function()
var channelOptions =
tags: "".split(" "),
id: "1"
;
initTagRenderer("".split(" "), "".split(" "), channelOptions);

StackExchange.using("externalEditor", function()
// Have to fire editor after snippets, if snippets enabled
if (StackExchange.settings.snippets.snippetsEnabled)
StackExchange.using("snippets", function()
createEditor();
);

else
createEditor();

);

function createEditor()
StackExchange.prepareEditor(
heartbeatType: 'answer',
autoActivateHeartbeat: false,
convertImagesToLinks: true,
noModals: true,
showLowRepImageUploadWarning: true,
reputationToPostImages: 10,
bindNavPrevention: true,
postfix: "",
imageUploader:
brandingHtml: "Powered by u003ca class="icon-imgur-white" href="https://imgur.com/"u003eu003c/au003e",
contentPolicyHtml: "User contributions licensed under u003ca href="https://creativecommons.org/licenses/by-sa/3.0/"u003ecc by-sa 3.0 with attribution requiredu003c/au003e u003ca href="https://stackoverflow.com/legal/content-policy"u003e(content policy)u003c/au003e",
allowUrls: true
,
onDemand: true,
discardSelector: ".discard-answer"
,immediatelyShowMarkdownHelp:true
);



);













draft saved

draft discarded


















StackExchange.ready(
function ()
StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f55329600%2flaravelhow-to-fix-sqlstate23000-integrity-constraint-violation%23new-answer', 'question_page');

);

Post as a guest















Required, but never shown

























1 Answer
1






active

oldest

votes








1 Answer
1






active

oldest

votes









active

oldest

votes






active

oldest

votes









0














This should solve the problem: you have to refresh your database (ps: you are going to re-insert your rows)



php artisan migrate refresh 





share|improve this answer

























  • Unfortunately, this solution does not work for me.

    – Yuliia
    Mar 25 at 0:22











  • I don't understand, how can I avoid re-adding?

    – Yuliia
    Mar 25 at 0:24















0














This should solve the problem: you have to refresh your database (ps: you are going to re-insert your rows)



php artisan migrate refresh 





share|improve this answer

























  • Unfortunately, this solution does not work for me.

    – Yuliia
    Mar 25 at 0:22











  • I don't understand, how can I avoid re-adding?

    – Yuliia
    Mar 25 at 0:24













0












0








0







This should solve the problem: you have to refresh your database (ps: you are going to re-insert your rows)



php artisan migrate refresh 





share|improve this answer















This should solve the problem: you have to refresh your database (ps: you are going to re-insert your rows)



php artisan migrate refresh 






share|improve this answer














share|improve this answer



share|improve this answer








edited Mar 25 at 4:31









Udhav Sarvaiya

2,81392132




2,81392132










answered Mar 25 at 0:10









YossYoss

1098




1098












  • Unfortunately, this solution does not work for me.

    – Yuliia
    Mar 25 at 0:22











  • I don't understand, how can I avoid re-adding?

    – Yuliia
    Mar 25 at 0:24

















  • Unfortunately, this solution does not work for me.

    – Yuliia
    Mar 25 at 0:22











  • I don't understand, how can I avoid re-adding?

    – Yuliia
    Mar 25 at 0:24
















Unfortunately, this solution does not work for me.

– Yuliia
Mar 25 at 0:22





Unfortunately, this solution does not work for me.

– Yuliia
Mar 25 at 0:22













I don't understand, how can I avoid re-adding?

– Yuliia
Mar 25 at 0:24





I don't understand, how can I avoid re-adding?

– Yuliia
Mar 25 at 0:24

















draft saved

draft discarded
















































Thanks for contributing an answer to Stack Overflow!


  • Please be sure to answer the question. Provide details and share your research!

But avoid …


  • Asking for help, clarification, or responding to other answers.

  • Making statements based on opinion; back them up with references or personal experience.

To learn more, see our tips on writing great answers.




draft saved


draft discarded














StackExchange.ready(
function ()
StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f55329600%2flaravelhow-to-fix-sqlstate23000-integrity-constraint-violation%23new-answer', 'question_page');

);

Post as a guest















Required, but never shown





















































Required, but never shown














Required, but never shown












Required, but never shown







Required, but never shown

































Required, but never shown














Required, but never shown












Required, but never shown







Required, but never shown







Popular posts from this blog

How to preserve electronics (computers, tablets and phones) for hundreds of years Announcing the arrival of Valued Associate #679: Cesar Manara Planned maintenance scheduled April 23, 2019 at 23:30 UTC (7:30pm US/Eastern) The network's official Twitter account is up and running again. What content…How might modern humans leave a message for 50,000 years?How would an aquatic race develop computers?How do we make computers care for human life?Keeping supplies for 1000 yearsWhat will cell phones become in 100 years?What body armor protects against a laser?Could a society attain 1800s technology if limited to using copper and bronze?Electricity power (magic) and electronicsScavenging metal resources in post-apocalypse after 100 yearsWhy would precursors create devices that can survive and still work after hundreds of years?

155 수학 과학 기타 둘러보기 메뉴eh추가해eh문서를 완성해

해남서초등학교 학교 연혁 학교 동문 외부 링크 둘러보기 메뉴북위 34° 34′ 21″ 동경 126° 35′ 50″ / 북위 34.5726385° 동경 126.5972670°  / 34.5726385; 126.5972670해남서초등학교eh