Ruby-on-rails Rails 新手,设置 db 然后运行 rake db:create/migrate
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/16758184/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me):
StackOverFlow
new to rails, setting up db then running rake db:create/migrate
提问by Harvey Katrina
hi im currently learning rails, and following a tutorial. the instructions were to edit the migration file after i've created the app, then running rake db:migrate, then rake db:create.
嗨,我目前正在学习 Rails,并遵循教程。说明是在我创建应用程序后编辑迁移文件,然后运行 rake db:migrate,然后运行 rake db:create。
i've edited the migration file to this:
我已将迁移文件编辑为:
class CreateUsers < ActiveRecord::Migration
def change
create_table :users do |t|
t.string :username
t.string :email
t.string :encrypted_password
t.string :salt
t.timestamps
end
end
end
then when i've run 'rake db:migrate' i got an error
然后当我运行“rake db:migrate”时出现错误
Mysql2::Error: Table 'users' already exists: CREATE TABLE `users` ...
after i'm supposed to run 'rake db:create', then im getting this
在我应该运行“rake db:create”之后,我得到了这个
user_auth_development already exists
user_auth_test already exists
回答by Jim Stewart
You run rake db:createonce and only once, and you run it first. Then you run rake db:migrateevery time you add/change a migration. You've either already run this migration, or you are pointing at a database that already exists and already contains a table named users. My guess is that you ran the migration once already, in which case you're probably good to go. If you want to nuke the DB and start over, do rake db:drop db:create db:migrate.
你rake db:create只运行一次,而且你先运行它。然后rake db:migrate每次添加/更改迁移时都运行。您要么已经运行了此迁移,要么指向一个已存在且已包含名为 的表的数据库users。我的猜测是您已经运行了一次迁移,在这种情况下,您可能很高兴。如果您想取消数据库并重新开始,请执行rake db:drop db:create db:migrate.
回答by Kannan S
We can simply give, it will do all the rake task which is require for database creation and migration
我们可以简单地给出,它将完成数据库创建和迁移所需的所有 rake 任务
rake db:setup
rake db:setup

