【发布时间】:2014-08-13 15:27:00
【问题描述】:
This is the error I am getting 当我尝试查看我使用 ruby on rails 创建的页面时。问题是,我已经将我的数据库从 mysql 迁移到了我的 ruby 应用程序。我可以在 schema.rb 文件夹中看到它
ActiveRecord::Schema.define(version: 0) do
create_table "users", force: true do |t|
t.string "first_name", null: false
t.string "last_name", null: false
t.string "username", null: false
t.string "password", null: false
t.string "email", null: false
end
end
这是我的迁移文件夹中的迁移文件
class CreateUsers < ActiveRecord::Migration
def change
create_table :users do |t|
t.timestamps
end
end
end
我要做的就是为该数据库运行一个脚手架,但我不断收到错误。
【问题讨论】:
-
您的表如何在没有迁移的情况下拥有这些列(first_name、last_name 等)?
-
define(version: 0) 表示数据库从未迁移过,当您迁移它时,此数字会更新为迁移时间戳,应该类似于:define(version: 20140810211014)。也许您的迁移由于某种原因没有成功,请尝试再次运行它们并检查是否有任何错误。
-
将
rake db:migrate --trace的输出添加到您的问题或要点中。 -
我摆脱了页面上的错误(通过我在以下答案中采取的行动)它将版本更改为 ActiveRecord::Schema.define(version: 20140813133141) 我猜是一件好事。但是,当我这样做时,它取出了有关数据库的所有信息 (t.string "first_name", null: false t.string "last_name", null: false)
标签: mysql ruby-on-rails ruby rails-activerecord rails-migrations