【问题标题】:Why does Cucumber drop tables if schema.rb is not present?如果 schema.rb 不存在,为什么 Cucumber 会删除表?
【发布时间】:2016-02-05 20:17:30
【问题描述】:

我有一个使用我无法控制的外部数据库的 Rails 4 应用程序。所以没有架构或迁移。无论如何,我创建了一个模型并使用 db 在模型中设置 table_name。

当我运行 cucumber 时,它会删除数据库表!? 知道为什么以及如何避免它吗?

$ bundle exec cucumber

Running via Spring preloader in process 18865

.../db/schema.rb doesn't exist yet. Run `rake 
db:migrate` to create it, then try again. If you do not intend to use a 
database, you should instead alter 
.../config/application.rb to limit the frameworks that 
will be loaded.

之后数据库为空,没有表。

【问题讨论】:

    标签: mysql ruby-on-rails ruby ruby-on-rails-4 cucumber


    【解决方案1】:

    如果 ActiveRecord 连接到数据库,您应该仍然能够在本地转储您的架构。

    rake db:schema:dump
    

    【讨论】:

    • 好吧,基本上你的意思是我应该创建 schema.rb。这解决了问题,但是如果我可以在没有它的情况下运行应用程序,为什么我应该这样做,即使我能够通过模型在数据库中写入。你知道我的意思吗?奇怪的是,schema 是 cucumber 的要求,而不是 rails 本身的要求。
    • 如果测试数据库是由测试框架创建的,这并不奇怪。
    猜你喜欢
    • 1970-01-01
    • 2018-08-31
    • 2018-02-25
    • 2022-10-13
    • 1970-01-01
    • 2018-09-27
    • 2012-06-06
    • 2011-03-26
    • 1970-01-01
    相关资源
    最近更新 更多