0

我有一个似乎导致问题的布尔字段。当我运行时heroku run rake db:reset,我得到这个结果:

rake aborted!
PGError: ERROR:  syntax error at or near "("
LINE 1: ...her_email" character varying(255), "admin" boolean(255) DEFA...
                                                             ^
: CREATE TABLE "users" ("id" serial primary key, "name" character varying(255), "email" character varying(255), "other_email" character varying(255), "admin" boolean(255) DEFAULT 'f', "password_digest" character varying(255), "created_at" timestamp NOT NULL, "updated_at" timestamp NOT NULL, "auth_token" character varying(255), "password_reset_token" character varying(255), "password_reset_sent_at" timestamp, "plant_id" integer, "invoice" boolean)

这是有问题的迁移:

class CreateUsers < ActiveRecord::Migration
  def change
    create_table :users do |t|
      t.string :name
      t.string :email
      t.string :other_email
      t.boolean :admin, :default => false, :null => false
      t.string :password_digest

      t.timestamps
    end
  end
end

我不确定为什么将字段长度添加到布尔字段中。有没有办法覆盖这种行为?

4

1 回答 1

1

检查你的schema.rb文件,你可能会在那里找到

t.boolean  "admin", :limit => 255

您可以创建迁移

change_column :users, :admin, :boolean, :limit => nil

我想您也可以添加:limit => nilcreate_table迁移中。您可能还必须rake db:migrate在开发环境中运行并在schema.rb没有:limit生产的情况下提交新的。

于 2012-07-28T08:55:24.083 回答