我是ruby和mysql的新手。
我被告知要执行以下两个命令:
mysql -u root; then CREATE DATABASE sd
rake db:migrate
。
创建时sd数据库为空。在我运行第二个命令后,sd充满了各个项目。
我想知道rake如何知道目的地是sd以及源是什么。
我知道db / migrate文件夹下有一些脚本,所以我想rake知道目标是来自这样新创建的(我假设,因为我是ruby的新手)脚本。但是来源呢?
谢谢!
答案 0 :(得分:0)
看起来您正在尝试使用Rails应用程序。我建议看一下config / database.yml。该文件包含测试,开发和生产环境的配置数据。默认情况下,rails使用开发环境。您可能会在开发部分的config / database.yml中找到答案。
答案 1 :(得分:0)
有关您数据库的所有信息都在config/database.yml
文件中。该文档可以为您提供帮助:http://guides.rubyonrails.org/configuring.html#configuring-a-database
你可以改变这个:
mysql -u root; then CREATE DATABASE sd
为此:
rake db:create
答案 2 :(得分:0)
如您所知,数据源通常由db / migrate / * .rb文件控制。
但是他们可能已经将另一个任务挂钩到db:通过Rakefile或lib / tasks / *。rake文件进行迁移,因此“rake db:mirgrate”也可以运行一些额外的任务。添加种子信息的常见任务是rake db:seed任务,它通常运行db / seeds.rb。
当我使用db / seeds.rb时,我通常将我的种子数据放在db / fixtures / *。yml中,但其他人可能有不同的位置。
在较新的rails上你也可以使用rake db:create
来创建数据库(假设database.yml中的用户具有足够的权限)。 rake -T db
会告诉你wnat任务已经用db命名,例如:
$ rake -T db
rake db:create # Create the database from DATABASE_URL or config/database.yml for the current Rails.env (use db:create:all to create all dbs in the config)
rake db:drop # Drops the database using DATABASE_URL or the current Rails.env (use db:drop:all to drop all databases)
rake db:fixtures:load # Load fixtures into the current environment's database.
rake db:migrate # Migrate the database (options: VERSION=x, VERBOSE=false).
rake db:migrate:status # Display status of migrations
rake db:rollback # Rolls the schema back to the previous version (specify steps w/ STEP=n).
rake db:schema:dump # Create a db/schema.rb file that can be portably used against any DB supported by AR
rake db:schema:load # Load a schema.rb file into the database
rake db:seed # Load the seed data from db/seeds.rb
rake db:seed_fu # Loads seed data for the current environment.
rake db:setup # Create the database, load the schema, and initialize with the seed data (use db:reset to also drop the db first)
rake db:structure:dump # Dump the database structure to db/structure.sql. Specify another file with DB_STRUCTURE=db/my_structure.sql
rake db:test:seed # seed the test database
rake db:version # Retrieves the current schema version number