使用外键创建表时的Laravel迁移错误

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'

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

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');
            }
        }