English 中文(简体)
在任何“削减”职能触发的情况下,是否有办法消除外国的主要制约因素?
原标题:Is there a way to disable foreign key constraints when any "down" function triggers?

I m 讨论执行<代码>的有效办法 Schema:disableForeignKeyConstraints (, 每当一个artisan移民:refresh 执行指挥。 例如,我们可以在<条码>下()方法中将其融入migration文档。 例如:

public function down()
{
    Schema::disableForeignKeyConstraints(); // Disable foreign key constraints
    Schema::dropIfExists( table ); // Delete the table
    Schema::enableForeignKeyConstraints(); // Re-enable foreign key constraints
}

是否有一项旨在降低表率的活动,我们可以通过在<条码>中援引该表加以利用。 AppserviceProvider? 这将比在每个移民档案中增加这两条线更为简化的解决办法。

问题回答

你可以发挥更积极的作用,处理此事。 然后,你可以在<条码>下的方法中指定这一助手职能。

if (!function_exists( drop_table_with_fk )) {
    function drop_table_with_fk($table)
    {
        IlluminateSupportFacadesSchema::disableForeignKeyConstraints();
        IlluminateSupportFacadesSchema::dropIfExists($table);
        IlluminateSupportFacadesSchema::enableForeignKeyConstraints();
    }
}

在<代码>app/Helpers目录中的新档案中保留这一功能(如果该名录存在的话,可能需要制作该名录)。 然后,你可以通过在<代码>composer.json文档中添加该目录,使该目录自动上载。

"autoload": {
    "files": [
        "app/Helpers/your_helper_file.php"
    ]
}

在修改<代码>composer.json 文档之后,运行composerump-autoload,以重新编制自动载荷文档。 现在,你可以在<条码><<><>>/代码>方法上使用<条码>。

public function down()
{
    drop_table_with_fk( table );
}




相关问题
Help with Estimating a Data Migration

Our client has a completely custom CMS that was built in ASP 1.1 and later upgraded to 2.0. The database has over 200 tables, and unfortunately, there s no documentation for either the ASP code or the ...

Migrate from MySQL to PostgreSQL on Linux (Kubuntu)

A long time ago on a system far, far away... Trying to migrate a database from MySQL to PostgreSQL. All the documentation I have read covers, in great detail, how to migrate the structure. I have ...

should i advocate migrating from access to (my)sql

We have a windows MFC app that is written against an access database on a company server. The db is not that big: 19 MB. There are at most 2-3 users accessing it at any one time. It is used in a ...

Database migrations for SQL Server

I need a database migration framework for SQL Server, capable of managing both schema changes and data migrations. I guess I am looking for something similar to django s South framework here. Given ...

Database migration

We are migrating a client s own database schema to our own (both SQL-Server). Most of the mappings from their schema to ours have been indentified and rules been agreed on if the columns don t exactly ...

Drupal 6 - Permissions issue after migration

My Database was quite large with lots of test data in tables like watchdog, access log,etc.. and I was running in to some trouble uploading. Then I proceeded to dive into the database and started ...

Migrating from SQL Server 2000 to SQL Server 2008

I need to migrate SQL Server 2000 databases to SQL Server 2008 and need to formalize a generic strategy for this migration. Need a ordered list of activities which should be done to achieve this.

热门标签