ruby-on-rails – rake db:test:准备不创建所有表

前端之家收集整理的这篇文章主要介绍了ruby-on-rails – rake db:test:准备不创建所有表前端之家小编觉得挺不错的,现在分享给大家,也给大家做个参考。
注意:使用Rails 3.0.7,Postgresql 8.4.4-1,rake 0.8.7.

试图让rails测试工作.

命令rake db:test:prepare似乎工作正常 –

  1. $rake db:test:prepare -t
  2. (in /home/beau/looked)
  3. ** Invoke db:test:prepare (first_time)
  4. ** Invoke db:abort_if_pending_migrations (first_time)
  5. ** Invoke environment (first_time)
  6. ** Execute environment
  7. ** Execute db:abort_if_pending_migrations
  8. ** Execute db:test:prepare
  9. ** Invoke db:test:load (first_time)
  10. ** Invoke db:test:purge (first_time)
  11. ** Invoke environment
  12. ** Execute db:test:purge
  13. ** Execute db:test:load
  14. ** Invoke db:schema:load (first_time)
  15. ** Invoke environment
  16. ** Execute db:schema:load
  17. NOTICE: CREATE TABLE will create implicit sequence "slugs_id_seq" for serial column "slugs.id"
  18. NOTICE: CREATE TABLE / PRIMARY KEY will create implicit index "slugs_pkey" for table "slugs"

但是有些表没有被创建.

这些是“开发”表:

  1. $psql -d looked -U admin -c '\d'
  2.  
  3. List of relations
  4. Schema | Name | Type | Owner
  5. --------+-------------------+----------+-------
  6. public | businesses | table | admin
  7. public | businesses_id_seq | sequence | admin
  8. public | categories | table | admin
  9. public | categories_id_seq | sequence | admin
  10. public | schema_migrations | table | admin
  11. public | slugs | table | admin
  12. public | slugs_id_seq | sequence | admin
  13. (7 rows)

rake创建的表:db:为测试环境做准备 –

  1. $psql -d looked_test -U admin -c '\d'
  2. List of relations
  3. Schema | Name | Type | Owner
  4. --------+-------------------+----------+-------
  5. public | categories | table | admin
  6. public | schema_migrations | table | admin
  7. public | slugs | table | admin
  8. public | slugs_id_seq | sequence | admin
  9. (4 rows)

正如您所看到的,它创建了一些表,但没有创建business,business_id_seq或categories_id_seq.

我不知道为什么,有人可以帮助我吗?

解决方法

首先确保在rake db:test:prepare之前运行rake db:migrate.

如果这不起作用,请在某处备份schema.rb,删除它,然后在运行rake db:test:prepare之前运行rake db:schema:dump.这将确保您的schema.rb文件完全反映您的数据库.

猜你在找的Ruby相关文章