【问题标题】:Windows and SQLite3 to Ubuntu and PostgreSQL migration issueWindows 和 SQLite3 到 Ubuntu 和 PostgreSQL 的迁移问题
【发布时间】:2013-02-19 05:03:13
【问题描述】:

我的开发环境在 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 没问题,这就是我没有发布它的原因。

【问题讨论】:

    标签: ruby-on-rails ruby postgresql ubuntu


    【解决方案1】:

    我需要

    rake db:schema:load
    

    我是个白痴。

    【讨论】:

      【解决方案2】:

      我看到了错误:

      uninitialized constant AddUsernameToUsers
      

      并搜索您的代码,我只看到一个名为AddUsernameToUser 的类。所以,这是一个开始的地方。

      【讨论】:

      • 我做到了,谢谢!现在我明白了……我有属于他们的“用户”和“项目”。我已经使用 rake create:db:all... 成功创建了数据库,但不确定为什么尚未创建“项目”。最初,我使用脚手架在 Windows 环境中创建它。 == AddTitleToItems:迁移 ============================================= === -- add_column(:items, :title, :string) rake 中止!发生错误,此迁移和所有后续迁移均已取消:PG::Error: ERROR: relationship "items" does not exist
      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2017-02-14
      • 1970-01-01
      • 2016-04-13
      • 1970-01-01
      • 2012-07-02
      • 2022-12-03
      相关资源
      最近更新 更多