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;
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, CONSTRAINTprojects_status_id_foreignFOREIGN
KEY (status_id) REFERENCESstatus_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
projectsaddstatus_idint unsigned null)
How can I fix this?
database laravel migration
add a comment |
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, CONSTRAINTprojects_status_id_foreignFOREIGN
KEY (status_id) REFERENCESstatus_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
projectsaddstatus_idint unsigned null)
How can I fix this?
database laravel migration
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 andphp artisan migrate:refresh.
– senty
Mar 25 at 1:32
add a comment |
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, CONSTRAINTprojects_status_id_foreignFOREIGN
KEY (status_id) REFERENCESstatus_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
projectsaddstatus_idint unsigned null)
How can I fix this?
database laravel migration
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, CONSTRAINTprojects_status_id_foreignFOREIGN
KEY (status_id) REFERENCESstatus_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
projectsaddstatus_idint unsigned null)
How can I fix this?
database laravel migration
database laravel migration
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 andphp artisan migrate:refresh.
– senty
Mar 25 at 1:32
add a comment |
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 andphp 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
add a comment |
1 Answer
1
active
oldest
votes
This should solve the problem: you have to refresh your database (ps: you are going to re-insert your rows)
php artisan migrate refresh
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
add a comment |
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
);
);
Sign up or log in
StackExchange.ready(function ()
StackExchange.helpers.onClickDraftSave('#login-link');
);
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
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
This should solve the problem: you have to refresh your database (ps: you are going to re-insert your rows)
php artisan migrate refresh
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
add a comment |
This should solve the problem: you have to refresh your database (ps: you are going to re-insert your rows)
php artisan migrate refresh
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
add a comment |
This should solve the problem: you have to refresh your database (ps: you are going to re-insert your rows)
php artisan migrate refresh
This should solve the problem: you have to refresh your database (ps: you are going to re-insert your rows)
php artisan migrate refresh
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
add a comment |
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
add a comment |
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.
Sign up or log in
StackExchange.ready(function ()
StackExchange.helpers.onClickDraftSave('#login-link');
);
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
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
Sign up or log in
StackExchange.ready(function ()
StackExchange.helpers.onClickDraftSave('#login-link');
);
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function ()
StackExchange.helpers.onClickDraftSave('#login-link');
);
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function ()
StackExchange.helpers.onClickDraftSave('#login-link');
);
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
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
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 andphp artisan migrate:refresh.– senty
Mar 25 at 1:32