我用的是Rails 2.3.4
当我执行rake db:test:prepare时,创建的id字段不是主键,而是自动递增的。
当我查看开发数据库时,主键没有问题。
使用mysql。
编辑:我的schema.rb文件似乎已更改:id=>false应为true。什么生成这个文件?数据库迁移?
[编辑]生成schema.rb文件的实际机制是什么?

最佳答案

执行rake任务时,如果未指定环境,则任务将执行到默认环境。
测试和开发数据库之间可能有不同的模式版本。

rake db:reset #drops and created the database for current environment
rake db:reset:all #drops and creates database for all environments
rake db:migrate #migrates the schema for the current environment
rake db:migrate RAILS_ENV=test #migrates the schema for the test environment

如果我没有错(我现在记得)
rake db:migrate #applies the migrations and dumps the schema to db/schema.rb file
rake db:schema:dump #dumps the actual state of your current environment schema into db/schema.rb file

10-07 19:42
查看更多