I'm in trouble because I can't execute "drioForeign" to remove foreign key constraints in laravel.
・ Status
The situation is exactly the same as the following qiita article.
Set onDelete/onUpdate of foreign key constraints after migration with Laravel + logical delete I was addicted
In other words, because I set a foreign key constraint without the onDelete option, I want to remove the foreign key constraint and set it again.
The official reference also states that it can be canceled by putting "'table name_column name_foreign'" in dropForeign.
Your laravelver5.8 reference
It was, but when I actually tried to create a migration file and run it, an error occurred and I could not run it.
Error screen ↓
] (6b9721a1218fcf9f4c3e78bcee81a14f.png)
The table was actually show indexed and compared with the description in the migration file.
Column details ↓
Code in migration file ↓
<? php
use Illuminate \ Support \ Facades \ Schema;
use Illuminate \ Database \ Schema \ Blueprint;
use Illuminate \ Database \ Migrations \ Migration;
class ChangeDrillsDropForeignCategoryId extends Migration
{
/ **
* Run the migrations.
*
* @return void
* /
public function up ()
{
Schema :: table ('drills', function (Blueprint $table) {
$table->dropForeign ('drills_cateory_id_foreign');
});
}
/ **
* Reverse the migrations.
*
* @return void
* /
public function down ()
{
Schema :: table ('drills', function (Blueprint $table) {
//
});
}
}
・ Other points to remember
Although it is the categories table that is the external constraint destination of category_id of drills,
When the external constraint was initially set, it was named "caterorys".
Later renamed "categories" due to the SQL issued by laravel.
・ What I did
I thought that it should be changed from "categories" (current table name) to "categorys" (table name at the time of external constraint setting) in order to release the external constraint, so I tried dropForeign after renaming the name.
can't be executed with an error.
I'm sorry for the long sentence, but if you give me some advice, I'll be saved!
-
Answer # 1
Related articles
- php - foreign key constraint on laravel phone number
- error when upgrading laravel 6x → 7x cannot be resolved
- php - i cannot submit in laravel
- php - the view cannot be displayed in laravel
- laravel 54 development environment only env("app_env") cannot be taken
- php - [laravel] cannot view registered data in view $tags is undefined
- php - [laravel] [mysql] cannot add data from form to database
- apache - the laravel route cannot be set properly
- php - app development with laravel: cannot get api key described in env file
- php - cannot download csv with laravel
- laravel - the class you are defining cannot be found
- laravel - cannot override customized validation message
- php - laravel error cannot be resolved
- laravel 5 - \ debugbar :: info () cannot be used in laravel debug bar
- laravel - i issued an ssl self-certificate with openssl, but cannot access due to a privacy error
- ruby - cannot save foreign key !!!!!!!!!!!
- php - cannot update with laravel: put
- laravel - cannot fix npm run dev error
- i would like to know how to write a foreign key constraint on an internal table in mysql
- cannot add vuejs component with laravel
- php - coincheck api authentication doesn't work
- php - i would like to introduce the coincheck api so that i can make payments with bitcoin on my ec site
- [php] i want to get account information using coincheck api
- python - you may need to restart the kernel to use updated packages error
- the emulator process for avd pixel_2_api_29 was killed occurred when the android studio emulator was started, so i would like to
- python 3x - typeerror: 'method' object is not subscriptable
- javascript - how to check if an element exists in puppeteer
- xcode - pod install [!] no `podfile 'found in the project directory
- i want to call a child component method from a parent in vuejs
- vuejs - [vuetify] unable to locate target [data-app] i want to unit test to avoid warning
Self-solved.
At the time of the image shown in the details of the column, it seems that the foreign key constraint was released.
When using dropForeign method, it seems that the key name remains in key_name even if the constraint is removed.
Check the details of the table in SHOW CREATE TABLES,
We were able to confirm exactly the external reference whether the table and the column to be referred to were specified in the "CONSTRAINT" column.