【问题标题】:Rails database migration failing because of Postgres inet type由于 Postgres inet 类型,Rails 数据库迁移失败
【发布时间】:2014-11-12 02:24:59
【问题描述】:

我有一个在 Heroku 上运行良好的 Rails(4.1.0) 应用程序。但是,在我的本地计算机上,rake db:migrate 失败,因为设计表使用 inet 数据类型,而我正在使用 sqlite3 进行测试。

我已经包含了 postgres gem 以及 postgres_ext 但仍然出现错误:

undefined method `inet' for #<ActiveRecord::ConnectionAdapters::Table:0x00000005fae9e8>/home/app/db/migrate/20141107192501_add_devise_to_users.rb:19:in `block in up'

【问题讨论】:

  • 什么是有问题的设计模块?
  • 可跟踪,当它尝试为 current_sign_in_ip 和 last_sign_in_ip 创建表列时。两者都是 inet 类型。
  • 在本地使用 Postgres 是一种选择吗?
  • 是的,我已经安装了 postgres 9.3。我为开发环境添加了 pg gem,但仍然遇到同样的问题。我觉得这里有些东西我完全错过了。
  • 您的database.yml 中是否设置了 Postgres?

标签: ruby-on-rails postgresql heroku devise


【解决方案1】:

如果可以接受使用 Postgres 进行本地测试,只需设置正确的适配器即可。样本database.yml

common: &common
  adapter: postgresql
  encoding: utf8
  template: template0 # Required for UTF8 encoding
  username: <%= ENV["POSTGRES_USER"] %>
  password: <%= ENV["POSTGRES_PASSWORD"] %>
  host: <%= ENV["POSTGRES_HOST"] %>

development:
  <<: *common
  database: 'my_app_dev'

# Warning: The database defined as "test" will be erased and
# re-generated from your development database when you run "rake".
# Do not set this db to the same as development or production.
test:
  <<: *common
  database: 'my_app_test'

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 2020-10-30
    • 2023-03-14
    • 1970-01-01
    • 2014-08-02
    • 1970-01-01
    • 2018-05-21
    • 2012-03-14
    • 2020-04-10
    相关资源
    最近更新 更多