我在 Windows 中有我的开发环境,有人建议我将它从 Windows 转移到 Ubuntu,并将数据库从库存 SQLite3 更改为 PostgreSQL。原因是实现搜索会更容易。
我试图在 Windows 中将其设为 PostgreSQL,但一直遇到一个错误。现在我已经在 Ubuntu 中启动并运行它,我收到了相同的错误消息。
20130218175105_devise_create_users.rb:
class DeviseCreateUsers < ActiveRecord::Migration
def change
create_table(:users) do |t|
## Database authenticatable
t.string :email, :null => false, :default => ""
t.string :encrypted_password, :null => false, :default => ""
## Recoverable
t.string :reset_password_token
t.datetime :reset_password_sent_at
## Rememberable
t.datetime :remember_created_at
## Trackable
t.integer :sign_in_count, :default => 0
t.datetime :current_sign_in_at
t.datetime :last_sign_in_at
t.string :current_sign_in_ip
t.string :last_sign_in_ip
## Confirmable
# t.string :confirmation_token
# t.datetime :confirmed_at
# t.datetime :confirmation_sent_at
# t.string :unconfirmed_email # Only if using reconfirmable
## Lockable
# t.integer :failed_attempts, :default => 0 # Only if lock strategy is :failed_attempts
# t.string :unlock_token # Only if unlock strategy is :email or :both
# t.datetime :locked_at
## Token authenticatable
# t.string :authentication_token
t.timestamps
end
add_index :users, :email, :unique => true
add_index :users, :reset_password_token, :unique => true
# add_index :users, :confirmation_token, :unique => true
# add_index :users, :unlock_token, :unique => true
# add_index :users, :authentication_token, :unique => true
end
end
20130224193041_add_username_to_users.rb:
class AddUsernameToUser < ActiveRecord::Migration
def change
add_column :users, :username, :string
end
end
20130225171914_add_title_to_items.rb:
class AddTitleToItems < ActiveRecord::Migration
def change
add_column :items, :title, :string
end
end
20130303014952_add_city_state_to_users.rb:
class AddCityStateToUsers < ActiveRecord::Migration
def change
add_column :users, :city, :string
add_column :users, :state, :string
end
end
数据库.yml:
development:
adapter: postgresql
encoding: unicode
database: scratch_development
pool: 5
timeout: 5000
username: postgres
password: harley
host: localhost
错误:
mike@ubuntu:~/Sites/scratch$ rake db:migrate
== DeviseCreateUsers: migrating ==============================================
-- create_table(:users)
NOTICE: CREATE TABLE will create implicit sequence "users_id_seq" for serial column "users.id"
NOTICE: CREATE TABLE / PRIMARY KEY will create implicit index "users_pkey" for table "users"
-> 0.0452s
-- add_index(:users, :email, {:unique=>true})
-> 0.0151s
-- add_index(:users, :reset_password_token, {:unique=>true})
-> 0.0309s
== DeviseCreateUsers: migrated (0.0921s) =====================================
rake aborted!
An error has occurred, this and all later migrations canceled:
uninitialized constant AddUsernameToUsers
/home/mike/.rvm/gems/ruby-1.9.3-p125/gems/activesupport-3.2.1/lib/active_support/inflector/methods.rb:229:in `block in constantize'
/home/mike/.rvm/gems/ruby-1.9.3-p125/gems/activesupport-3.2.1/lib/active_support/inflector/methods.rb:228:in `each'
/home/mike/.rvm/gems/ruby-1.9.3-p125/gems/activesupport-3.2.1/lib/active_support/inflector/methods.rb:228:in `constantize'
/home/mike/.rvm/gems/ruby-1.9.3-p125/gems/activesupport-3.2.1/lib/active_support/core_ext/string/inflections.rb:54:in `constantize'
/home/mike/.rvm/gems/ruby-1.9.3-p125/gems/activerecord-3.2.1/lib/active_record/migration.rb:522:in `load_migration'
/home/mike/.rvm/gems/ruby-1.9.3-p125/gems/activerecord-3.2.1/lib/active_record/migration.rb:517:in `migration'
/home/mike/.rvm/gems/ruby-1.9.3-p125/gems/activerecord-3.2.1/lib/active_record/migration.rb:512:in `migrate'
/home/mike/.rvm/gems/ruby-1.9.3-p125/gems/activerecord-3.2.1/lib/active_record/migration.rb:704:in `block (2 levels) in migrate'
/home/mike/.rvm/gems/ruby-1.9.3-p125/gems/activerecord-3.2.1/lib/active_record/migration.rb:759:in `call'
/home/mike/.rvm/gems/ruby-1.9.3-p125/gems/activerecord-3.2.1/lib/active_record/migration.rb:759:in `block in ddl_transaction'
/home/mike/.rvm/gems/ruby-1.9.3-p125/gems/activerecord-3.2.1/lib/active_record/connection_adapters/abstract/database_statements.rb:190:in `transaction'
/home/mike/.rvm/gems/ruby-1.9.3-p125/gems/activerecord-3.2.1/lib/active_record/transactions.rb:208:in `transaction'
/home/mike/.rvm/gems/ruby-1.9.3-p125/gems/activerecord-3.2.1/lib/active_record/migration.rb:759:in `ddl_transaction'
/home/mike/.rvm/gems/ruby-1.9.3-p125/gems/activerecord-3.2.1/lib/active_record/migration.rb:703:in `block in migrate'
/home/mike/.rvm/gems/ruby-1.9.3-p125/gems/activerecord-3.2.1/lib/active_record/migration.rb:684:in `each'
/home/mike/.rvm/gems/ruby-1.9.3-p125/gems/activerecord-3.2.1/lib/active_record/migration.rb:684:in `migrate'
/home/mike/.rvm/gems/ruby-1.9.3-p125/gems/activerecord-3.2.1/lib/active_record/migration.rb:554:in `up'
/home/mike/.rvm/gems/ruby-1.9.3-p125/gems/activerecord-3.2.1/lib/active_record/migration.rb:535:in `migrate'
/home/mike/.rvm/gems/ruby-1.9.3-p125/gems/activerecord-3.2.1/lib/active_record/railties/databases.rake:153:in `block (2 levels) in <top (required)>'
/home/mike/.rvm/gems/ruby-1.9.3-p125/bin/ruby_noexec_wrapper:14:in `eval'
/home/mike/.rvm/gems/ruby-1.9.3-p125/bin/ruby_noexec_wrapper:14:in `<main>'
Tasks: TOP => db:migrate
(See full trace by running task with --trace)
我 99% 确定我的 gemfile 没问题,这就是我没有发布它的原因。