简体   繁体   English

Rails没有创建任何数据库目录

[英]Rails didn't create any db directory

While I'm creating a new rails app, there is no db directory while skipping active record for using mongodb later, By this command. 当我创建一个新的Rails应用程序时,没有数据库目录,而跳过活动记录供以后使用mongodb,请通过此命令。

rails new app-name --skip-active-record

where rails new app-name created db as expected. rails new app-name按预期创建了数据库。 And so, rake db:create or rake db:migrate don't act expectedly. 因此, rake db:createrake db:migrate预期不会起作用。 I need to edit /db/seeds.rb & i cann't find it. 我需要编辑/db/seeds.rb ,但找不到。

I tried some post fixing, nothing brings the missing directory. 我尝试了一些后期修复,没有带来丢失的目录。 I'm new in rails. 我是新手。 Have I missed something? 我错过了什么吗? Thanks for cooperating. 感谢您的合作。

By including --skip-active-record in the new command, you are telling Rails to not generate the database files, which is correct if you want to use MongoDB! 通过在新命令中包括--skip-active-record ,您可以告诉Rails不要生成数据库文件,如果您想使用MongoDB,这是正确的!

Next, you need to remove the sqlite gem from your gemfile and add the MongoDb gem to the gem file. 接下来,您需要从gemfile中删除sqlite gem,并将MongoDb gem添加到gem文件中。 Here is the Ruby Gems page for MongoDB , just copy the gemfile reference from there and paste it into your gemfile. 这是MongoDB的Ruby Gems页面 ,只需从那里复制gemfile引用并将其粘贴到您的gemfile中即可。 You always need to run the bundle command after altering your gemfile 更改gemfile之后,您始终需要运行bundle命令

Then you run rails g mongoid:config and rails will generate the config/mongoid.yml for you. 然后运行rails g mongoid:config ,rails将为您生成config/mongoid.yml

Here is an article for reference: https://gorails.com/guides/setting-up-rails-4-with-mongodb-and-mongoid 以下是供参考的文章: https : //gorails.com/guides/setting-up-rails-4-with-mongodb-and-mongoid

MongoDB does not have a schema so you don't need migrations. MongoDB没有架构,因此您不需要迁移。 Thats kind of the whole point of a schema-less database. 那就是无模式数据库的重点。

db/seeds.rb is just a plain Ruby file thats executed when you run rake db:seed *. db/seeds.rb只是运行rake db:seed *时执行的普通Ruby文件。 You can create it by running $ touch db/seeds.rb . 您可以通过运行$ touch db/seeds.rb来创建它。 There is nothing magical about it. 没有什么神奇的。

If you are using Mongoid then everything you need is generated when you run: 如果您使用的是Mongoid,则在运行时会生成所需的一切:

$ rails g mongoid:config

So just relax. 所以放松一下。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM