问题描述
我在尝试使用 Postgres 在 Rails 4 中进行基本模型生成和迁移时遇到了很多问题.我安装了 pg
gem,版本 0.17.1
.
I'm running into a LOT of problems just trying to do basic model generations and migrations in Rails 4 with Postgres. I have the pg
gem installed, version 0.17.1
.
一开始,我什至无法在没有错误的情况下运行迁移,因为 schema_migrations
表是使用 version
列创建的,其维度为 1.一旦我手动将其更改为零,它就可以正常工作.
In the beginning, I couldn't even run migrations without errors, because the
schema_migrations
table was created with the version
column having a dimension of 1
. Once I manually changed it to zero, it worked fine.
现在,如果我查看使用 Rails 模型生成器导致的所有迁移,我会看到每一列,id
列,是用1
的dimension
创建的.
Now, if I look at all of the migrations that resulted from me using the Rails model generator, I see that every single column, with the exception of the id
column in each table, was created with dimension
of 1
.
是否需要更改某些默认设置?这在某种程度上是正确的,我在搞砸其他事情吗?这是我的第一个 Rails 4 项目,所以我只是想弄清楚为什么它希望所有这些列都默认为数组.
Is there some default setting I need to change? Is this somehow correct and I am messing up something else? This is my first Rails 4 project, so I'm just trying to figure out why it would want all of those columns to default to an Array.
这是我的迁移文件之一:
Here is one of my migration files:
class CreateCatalogs < ActiveRecord::Migration
def change
create_table :catalogs do |t|
t.string :name
t.text :description
t.string :schema_name
t.string :catalog_type
t.boolean :billable
t.timestamps
end
end
end
这是来自schema.rb
:
create_table "catalogs", force: true do |t|
t.string "name", array: true
t.text "description", array: true
t.string "schema_name", array: true
t.string "catalog_type", array: true
t.boolean "billable", array: true
t.datetime "created_at", array: true
t.datetime "updated_at", array: true
end
什么鬼!
推荐答案
幸运的是,Ruby on Rails v4.0.3
今天.我做了以下事情:
As luck would have it, Ruby on Rails v4.0.3
was released today. I did the following:
- 升级 Rails
- 删除了
db/migrate/schema.rb
- 删除所有 3 个数据库(开发、测试、生产)
- 运行
rake db:setup
- 运行
rake db:migrate
- 查看新的
db/migrate/schema.rb
以确保它没问题 - 运行
rake db:test:prepare
- Upgrade Rails
- deleted
db/migrate/schema.rb
- Delete all 3 databases (dev, test, production)
- ran
rake db:setup
- ran
rake db:migrate
- Looked at the new
db/migrate/schema.rb
to make sure it was OK - ran
rake db:test:prepare
果然,这个问题在这个新版本中得到了修复.我在任何地方都找不到问题的记录!这已经是几个星期的问题了.无论如何,固定!
Sure enough, the problem is fixed in this new release. I couldn't find a record of the problem anywhere! It's been an issue for a few weeks. Anyway, fixed!
这篇关于为什么我在 Rails 4/Postgres 中的所有表都是用“维度"创建的?1?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!