<legend id='bpKJ7'><style id='bpKJ7'><dir id='bpKJ7'><q id='bpKJ7'></q></dir></style></legend>
    • <bdo id='bpKJ7'></bdo><ul id='bpKJ7'></ul>
    <i id='bpKJ7'><tr id='bpKJ7'><dt id='bpKJ7'><q id='bpKJ7'><span id='bpKJ7'><b id='bpKJ7'><form id='bpKJ7'><ins id='bpKJ7'></ins><ul id='bpKJ7'></ul><sub id='bpKJ7'></sub></form><legend id='bpKJ7'></legend><bdo id='bpKJ7'><pre id='bpKJ7'><center id='bpKJ7'></center></pre></bdo></b><th id='bpKJ7'></th></span></q></dt></tr></i><div id='bpKJ7'><tfoot id='bpKJ7'></tfoot><dl id='bpKJ7'><fieldset id='bpKJ7'></fieldset></dl></div>

    1. <tfoot id='bpKJ7'></tfoot>
    2. <small id='bpKJ7'></small><noframes id='bpKJ7'>

      删除带有外键 Laravel 错误的列:一般错误:1025 重命名错误

      Dropping column with foreign key Laravel error: General error: 1025 Error on rename(删除带有外键 Laravel 错误的列:一般错误:1025 重命名错误)
      <i id='B6oIu'><tr id='B6oIu'><dt id='B6oIu'><q id='B6oIu'><span id='B6oIu'><b id='B6oIu'><form id='B6oIu'><ins id='B6oIu'></ins><ul id='B6oIu'></ul><sub id='B6oIu'></sub></form><legend id='B6oIu'></legend><bdo id='B6oIu'><pre id='B6oIu'><center id='B6oIu'></center></pre></bdo></b><th id='B6oIu'></th></span></q></dt></tr></i><div id='B6oIu'><tfoot id='B6oIu'></tfoot><dl id='B6oIu'><fieldset id='B6oIu'></fieldset></dl></div>

            <tbody id='B6oIu'></tbody>
          • <small id='B6oIu'></small><noframes id='B6oIu'>

            • <bdo id='B6oIu'></bdo><ul id='B6oIu'></ul>
              <legend id='B6oIu'><style id='B6oIu'><dir id='B6oIu'><q id='B6oIu'></q></dir></style></legend>

              1. <tfoot id='B6oIu'></tfoot>

                本文介绍了删除带有外键 Laravel 错误的列:一般错误:1025 重命名错误的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着跟版网的小编来一起学习吧!

                问题描述

                I've created a table using migration like this:

                public function up()
                {
                    Schema::create('despatch_discrepancies',  function($table) {
                        $table->increments('id')->unsigned();
                        $table->integer('pick_id')->unsigned();
                        $table->foreign('pick_id')->references('id')->on('picks');
                        $table->integer('pick_detail_id')->unsigned();
                        $table->foreign('pick_detail_id')->references('id')->on('pick_details');
                        $table->integer('original_qty')->unsigned();
                        $table->integer('shipped_qty')->unsigned();
                    });
                }
                
                public function down()
                {
                    Schema::drop('despatch_discrepancies');
                }
                

                I need to change this table and drop the foreign key reference & column pick_detail_id and add a new varchar column called sku after pick_id column.

                So, I've created another migration, which looks like this:

                public function up()
                {
                    Schema::table('despatch_discrepancies', function($table)
                    {
                        $table->dropForeign('pick_detail_id');
                        $table->dropColumn('pick_detail_id');
                        $table->string('sku', 20)->after('pick_id');
                    });
                }
                
                public function down()
                {
                    Schema::table('despatch_discrepancies', function($table)
                    {
                        $table->integer('pick_detail_id')->unsigned();
                        $table->foreign('pick_detail_id')->references('id')->on('pick_details');
                        $table->dropColumn('sku');
                    });
                }
                

                When I run this migration, I get the following error:

                [IlluminateDatabaseQueryException]
                SQLSTATE[HY000]: General error: 1025 Error on rename of './dev_iwms_reboot/despatch_discrepancies' to './dev_iwms_reboot/#sql2-67c-17c464' (errno: 152) (SQL: alter table despatch_discrepancies drop foreign key pick_detail_id)

                [PDOException]
                SQLSTATE[HY000]: General error: 1025 Error on rename of './dev_iwms_reboot/despatch_discrepancies' to './dev_iwms_reboot/#sql2-67c-17c464' (errno: 152)

                When I try to reverse this migration by running php artisan migrate:rollback command, I get a Rolled back message, but it's not actually doing anything in the database.

                Any idea what might be wrong? How do you drop a column that has a foreign key reference?

                解决方案

                It turns out; when you create a foreign key like this:

                $table->integer('pick_detail_id')->unsigned();
                $table->foreign('pick_detail_id')->references('id')->on('pick_details');
                

                Laravel uniquely names the foreign key reference like this:

                <table_name>_<foreign_table_name>_<column_name>_foreign
                despatch_discrepancies_pick_detail_id_foreign (in my case)
                

                Therefore, when you want to drop a column with foreign key reference, you have to do it like this:

                $table->dropForeign('despatch_discrepancies_pick_detail_id_foreign');
                $table->dropColumn('pick_detail_id');
                

                Update:

                Laravel 4.2+ introduces a new naming convention:

                <table_name>_<column_name>_foreign
                

                这篇关于删除带有外键 Laravel 错误的列:一般错误:1025 重命名错误的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持跟版网!

                本站部分内容来源互联网,如果有图片或者内容侵犯了您的权益,请联系我们,我们会在确认后第一时间进行删除!

                相关文档推荐

                DeepL的翻译效果还是很强大的,如果我们要用php实现DeepL翻译调用,该怎么办呢?以下是代码示例,希望能够帮到需要的朋友。 在这里需要注意,这个DeepL的账户和api申请比较难,不支持中国大陆申请,需要拥有香港或者海外信用卡才行,没账号的话,目前某宝可以
                PHP通过phpspreadsheet导入Excel日期,导入系统后,全部变为了4开头的几位数字,这是为什么呢?原因很简单,将Excel的时间设置问文本,我们就能看到该日期本来的数值,上图对应的数值为: 要怎么解决呢?进行数据转换就行,这里可以封装方法,或者用第三方的
                mediatemple - can#39;t send email using codeigniter(mediatemple - 无法使用 codeigniter 发送电子邮件)
                Laravel Gmail Configuration Error(Laravel Gmail 配置错误)
                Problem with using PHPMailer for SMTP(将 PHPMailer 用于 SMTP 的问题)
                Issue on how to setup SMTP using PHPMailer in GoDaddy server(关于如何在 GoDaddy 服务器中使用 PHPMailer 设置 SMTP 的问题)

                  <tbody id='ELErG'></tbody>
                  • <bdo id='ELErG'></bdo><ul id='ELErG'></ul>
                  • <legend id='ELErG'><style id='ELErG'><dir id='ELErG'><q id='ELErG'></q></dir></style></legend>
                        <tfoot id='ELErG'></tfoot>
                        <i id='ELErG'><tr id='ELErG'><dt id='ELErG'><q id='ELErG'><span id='ELErG'><b id='ELErG'><form id='ELErG'><ins id='ELErG'></ins><ul id='ELErG'></ul><sub id='ELErG'></sub></form><legend id='ELErG'></legend><bdo id='ELErG'><pre id='ELErG'><center id='ELErG'></center></pre></bdo></b><th id='ELErG'></th></span></q></dt></tr></i><div id='ELErG'><tfoot id='ELErG'></tfoot><dl id='ELErG'><fieldset id='ELErG'></fieldset></dl></div>

                          <small id='ELErG'></small><noframes id='ELErG'>