0

I am using laravel's artisan command to create a database table with a foreign key. I'm getting the following error when I run the php artisan migrate command:

SQLSTATE[23000]: Integrity constraint violation: 1022 Can't write; duplicate key in table '#sql-73_ca' (SQL: alter table table_1 add constraint table_1_table_1_sid_foreign foreign key
(table_1_sid) references table_2 (id))

Also, I don't have a table '#sql-73_ca'

Sark
2992 silver badges21 bronze badges
asked Jan 4, 2018 at 10:10
3
  • 1
    share your migration snippets . Commented Jan 4, 2018 at 10:13
  • Could you please post the code of all relevant migrations? Commented Jan 4, 2018 at 10:13
  • can you plz share your both table migrations. Commented Jan 4, 2018 at 10:36

2 Answers 2

1

if you using phpmyadmin you should copy a section of error notification to the query sql in phpmyadmin:

" alter table table_1 add constraint table_1_table_1_sid_foreign 
foreign key (table_1_sid) references table_2 (id)"

It will display more information for error

answered Jan 4, 2018 at 11:28

Comments

0

Its about unique() command in your migration file. You should delete this if you dont wanna get error. Or add a function for if there is unique column. You should share your migration. We cant understand with this.

Also you can try this in related controller.

 try { //codes
} catch(\Illuminate\Database\QueryException $e){
 $errorCode = $e->errorInfo[1];
 if($errorCode == '1062'){
 echo('Error Message');
 }
 }
answered Jan 4, 2018 at 10:23

Comments

Your Answer

Draft saved
Draft discarded

Sign up or log in

Sign up using Google
Sign up using Email and Password

Post as a guest

Required, but never shown

Post as a guest

Required, but never shown

By clicking "Post Your Answer", you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.