gpt4 book ai didi

windows - Windows XAMPP 上的 Yii2 迁移/向下错误

转载 作者:可可西里 更新时间:2023-11-01 11:43:58 25 4
gpt4 key购买 nike

  1. 在 Windows 上运行 XAMPP 机器,我尝试运行命令:
    $ ./yii migrate/down    Yii Migration Tool (based on Yii v2.0.15.1)    Total 1 migration to be reverted:            m180614_020037_create_table_place_lang    Revert the above migration? (yes|no) [no]:yes    *** reverting m180614_020037_create_table_place_lang        > drop foreign key fk_place_lang_id_place from table place_lang ... done (time: 0.067s)        > drop index idx_place_lang_id_place on place_lang ... done (time: 0.189s)        > drop table place_lang ... done (time: 0.135s)    *** failed to revert m180614_020037_create_table_place_lang (time: 0.396s)    0 from 1 migrations were reverted.    Migration failed. The rest of the migrations are canceled.
  1. I ran the migration below

    use yii\db\Migration;// Class m180614_020037_create_table_place_langclass m180614_020037_create_table_place_lang extends Migration{    /**     * {@inheritdoc}     */    public function up()    {        $this->createTable('place_lang', [            'id' => $this->primaryKey()->unsigned(),            'place_id' => $this->integer(11)->unsigned()->notNull(),            'locality' => $this->string(45)->notNull(),            'country' => $this->string(45)->notNull(),            'lang' => $this->string(2)->notNull()        ]);
        $this->createIndex(
    'idx_place_lang_id_place',
    'place_lang',
    'place_id'
    );

    $this->addForeignKey(
    'fk_place_lang_id_place',
    'place_lang',
    'place_id',
    'place',
    'id'
    );


    }

    /**
    * {@inheritdoc}
    */
    public function down()
    {
    $this->dropForeignKey('fk_place_lang_id_place', 'place_lang');
    $this->dropIndex('idx_place_lang_id_place', 'place_lang');
    $this->dropTable('place_lang');

    return false;
    }
    }

    数据库表已删除,但迁移失败,我无法继续迁移堆栈。

在堆栈中的下方可以看到另一个迁移:

<?php

use yii\db\Migration;

/**
* Class m180614_015652_create_table_place
*/
class m180614_015652_create_table_place extends Migration
{
/**
* {@inheritdoc}
*/
public function up()
{
$this->createTable('place', [
'id' => $this->primaryKey()->unsigned()->notNull(),
'place_id' => $this->string(45)->notNull(),
'lat' => $this->string(45)->notNull(),
'lng' => $this->string(45)->notNull(),
'country_code' => $this->string(2)->notNull(),
'is_country' => $this->tinyInteger(4)->notNull()
]);
}

/**
* {@inheritdoc}
*/
public function down()
{
$this->dropTable('place');

return false;
}

}

这是 yii 2 在 Windows 和 XAMPP 上的限制,还是新手使用该框架的错误?

最佳答案

在迁移中返回false 标记为失败,所以是这个原因。这是记录在案的:

Not all migrations are reversible. For example, if the up() method deletes a row of a table, you may not be able to recover this row in the down() method. Sometimes, you may be just too lazy to implement the down(), because it is not very common to revert database migrations. In this case, you should return false in the down() method to indicate that the migration is not reversible.

https://www.yiiframework.com/doc/guide/2.0/en/db-migrations

如果您不想控制迁移流程,您可能不应该返回任何东西。


./yii migrate/refresh 之所以有效,是因为它不使用 down()。此命令从数据库中删除每个表并运行 migrate/up

关于windows - Windows XAMPP 上的 Yii2 迁移/向下错误,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/50868402/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com