运行heroku rake db:migrate aborted

时间:2011-04-07 08:08:44

标签: ruby-on-rails heroku

这是我的迁移文件:

class CreateUsers < ActiveRecord::Migration
  def self.up
    create_table :users do |t|
      t.string    :login,             :null => false                # optional, see below
      t.string    :crypted_password,    :null => false                # optional, see below
      t.string    :password_salt,       :null => false                # optional, but highly recommended
      t.string    :email,               :null => false                # optional, you can use login instead, or both
      t.string    :persistence_token,   :null => false                # required
      t.string    :single_access_token, :null => false                # optional, see Authlogic::Session::Params
      t.string    :perishable_token,    :null => false                # optional, see Authlogic::Session::Perishability

      # Magic columns, just like ActiveRecord's created_at and updated_at. These are automatically maintained by Authlogic if they are present.
      t.integer   :login_count,         :null => false, :default => 0 # optional, see Authlogic::Session::MagicColumns
      t.integer   :failed_login_count,  :null => false, :default => 0 # optional, see Authlogic::Session::MagicColumns
      t.datetime  :last_request_at                                    # optional, see Authlogic::Session::MagicColumns
      t.datetime  :current_login_at                                   # optional, see Authlogic::Session::MagicColumns
      t.datetime  :last_login_at                                      # optional, see Authlogic::Session::MagicColumns
      t.string    :current_login_ip                                   # optional, see Authlogic::Session::MagicColumns
      t.string    :last_login_ip                                      # optional, see Authlogic::Session::MagicColumns

      t.string    :name,                :null => false, :default => ''
      t.string    :gender,              :null => false, :default => ''
      t.datetime  :dob,                 :null => false, :default => ''
      t.timestamps
    end
  end

  def self.down
    drop_table :users
  end
end

如果我想将应用推送到heroku并运行heroku rake db:migrate,则会出现以下错误:

==  CreateUsers: migrating ====================================================
-- create_table(:users)
rake aborted!
An error has occurred, this and all later migrations canceled:

PGError: ERROR:  invalid input syntax for type timestamp: ""
: CREATE TABLE "users" ("id" serial primary key, "login" character varying(255) NOT NULL, "crypted_password" character varying(255) NOT NULL, "password_salt" character varying(255) NOT NULL, "email" character varying(255) NOT NULL, "persistence_token" character varying(255) NOT NULL, "single_access_token" character varying(255) NOT NULL, "perishable_token" character varying(255) NOT NULL, "login_count" integer DEFAULT 0 NOT NULL, "failed_login_count" integer DEFAULT 0 NOT NULL, "last_request_at" timestamp, "current_login_at" timestamp, "last_login_at" timestamp, "current_login_ip" character varying(255), "last_login_ip" character varying(255), "name" character varying(255) DEFAULT '' NOT NULL, "gender" character varying(255) DEFAULT '' NOT NULL, "dob" timestamp DEFAULT '' NOT NULL, "created_at" timestamp, "updated_at" timestamp) 

(See full trace by running task with --trace)

我做错了什么?谢谢。

1 个答案:

答案 0 :(得分:2)

你已经默认为''。这在Postgres中无效。将列类型更改为字符串或默认为null或创建新的日期对象并将其默认为