jjzjj

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

coder 2024-06-20 原文

  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_lang
    class 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/

有关windows - Windows XAMPP 上的 Yii2 迁移/向下错误的更多相关文章

  1. ruby-on-rails - Ruby on Rails 迁移,将表更改为 MyISAM - 2

    如何正确创建Rails迁移,以便将表更改为MySQL中的MyISAM?目前是InnoDB。运行原始执行语句会更改表,但它不会更新db/schema.rb,因此当在测试环境中重新创建表时,它会返回到InnoDB并且我的全文搜索失败。我如何着手更改/添加迁移,以便将现有表修改为MyISAM并更新schema.rb,以便我的数据库和相应的测试数据库得到相应更新? 最佳答案 我没有找到执行此操作的好方法。您可以像有人建议的那样更改您的schema.rb,然后运行:rakedb:schema:load,但是,这将覆盖您的数据。我的做法是(假设

  2. ruby - 在 Ruby 程序执行时阻止 Windows 7 PC 进入休眠状态 - 2

    我需要在客户计算机上运行Ruby应用程序。通常需要几天才能完成(复制大备份文件)。问题是如果启用sleep,它会中断应用程序。否则,计算机将持续运行数周,直到我下次访问为止。有什么方法可以防止执行期间休眠并让Windows在执行后休眠吗?欢迎任何疯狂的想法;-) 最佳答案 Here建议使用SetThreadExecutionStateWinAPI函数,使应用程序能够通知系统它正在使用中,从而防止系统在应用程序运行时进入休眠状态或关闭显示。像这样的东西:require'Win32API'ES_AWAYMODE_REQUIRED=0x0

  3. ruby-on-rails - Rails 常用字符串(用于通知和错误信息等) - 2

    大约一年前,我决定确保每个包含非唯一文本的Flash通知都将从模块中的方法中获取文本。我这样做的最初原因是为了避免一遍又一遍地输入相同的字符串。如果我想更改措辞,我可以在一个地方轻松完成,而且一遍又一遍地重复同一件事而出现拼写错误的可能性也会降低。我最终得到的是这样的:moduleMessagesdefformat_error_messages(errors)errors.map{|attribute,message|"Error:#{attribute.to_s.titleize}#{message}."}enddeferror_message_could_not_find(obje

  4. ruby - 使用 Vim Rails,您可以创建一个新的迁移文件并一次性打开它吗? - 2

    使用带有Rails插件的vim,您可以创建一个迁移文件,然后一次性打开该文件吗?textmate也可以这样吗? 最佳答案 你可以使用rails.vim然后做类似的事情::Rgeneratemigratonadd_foo_to_bar插件将打开迁移生成的文件,这正是您想要的。我不能代表textmate。 关于ruby-使用VimRails,您可以创建一个新的迁移文件并一次性打开它吗?,我们在StackOverflow上找到一个类似的问题: https://sta

  5. ruby-on-rails - date_field_tag,如何设置默认日期? [ rails 上的 ruby ] - 2

    我想设置一个默认日期,例如实际日期,我该如何设置?还有如何在组合框中设置默认值顺便问一下,date_field_tag和date_field之间有什么区别? 最佳答案 试试这个:将默认日期作为第二个参数传递。youcorrectlysetthedefaultvalueofcomboboxasshowninyourquestion. 关于ruby-on-rails-date_field_tag,如何设置默认日期?[rails上的ruby],我们在StackOverflow上找到一个类似的问

  6. ruby-on-rails - openshift 上的 rails 控制台 - 2

    我将我的Rails应用程序部署到OpenShift,它运行良好,但我无法在生产服务器上运行“Rails控制台”。它给了我这个错误。我该如何解决这个问题?我尝试更新ruby​​gems,但它也给出了权限被拒绝的错误,我也无法做到。railsc错误:Warning:You'reusingRubygems1.8.24withSpring.UpgradetoatleastRubygems2.1.0andrun`gempristine--all`forbetterstartupperformance./opt/rh/ruby193/root/usr/share/rubygems/rubygems

  7. ruby-on-rails - 迷你测试错误 : "NameError: uninitialized constant" - 2

    我遵循MichaelHartl的“RubyonRails教程:学习Web开发”,并创建了检查用户名和电子邮件长度有效性的测试(名称最多50个字符,电子邮件最多255个字符)。test/helpers/application_helper_test.rb的内容是:require'test_helper'classApplicationHelperTest在运行bundleexecraketest时,所有测试都通过了,但我看到以下消息在最后被标记为错误:ERROR["test_full_title_helper",ApplicationHelperTest,1.820016791]test

  8. ruby-on-rails - 相关表上的范围为 "WHERE ... LIKE" - 2

    我正在尝试从Postgresql表(table1)中获取数据,该表由另一个相关表(property)的字段(table2)过滤。在纯SQL中,我会这样编写查询:SELECT*FROMtable1JOINtable2USING(table2_id)WHEREtable2.propertyLIKE'query%'这工作正常:scope:my_scope,->(query){includes(:table2).where("table2.property":query)}但我真正需要的是使用LIKE运算符进行过滤,而不是严格相等。然而,这是行不通的:scope:my_scope,->(que

  9. ruby-on-rails - 如何在 Rails View 上显示错误消息? - 2

    我是rails的新手,想在form字段上应用验证。myviewsnew.html.erb.....模拟.rbclassSimulation{:in=>1..25,:message=>'Therowmustbebetween1and25'}end模拟Controller.rbclassSimulationsController我想检查模型类中row字段的整数范围,如果不在范围内则返回错误信息。我可以检查上面代码的范围,但无法返回错误消息提前致谢 最佳答案 关键是您使用的是模型表单,一种显示ActiveRecord模型实例属性的表单。c

  10. 使用 ACL 调用 upload_file 时出现 Ruby S3 "Access Denied"错误 - 2

    我正在尝试编写一个将文件上传到AWS并公开该文件的Ruby脚本。我做了以下事情:s3=Aws::S3::Resource.new(credentials:Aws::Credentials.new(KEY,SECRET),region:'us-west-2')obj=s3.bucket('stg-db').object('key')obj.upload_file(filename)这似乎工作正常,除了该文件不是公开可用的,而且我无法获得它的公共(public)URL。但是当我登录到S3时,我可以正常查看我的文件。为了使其公开可用,我将最后一行更改为obj.upload_file(file

随机推荐