Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

rake db:test:prepare not creating all tables

NOTE: Using Rails 3.0.7, Postgresql 8.4.4-1, rake 0.8.7.

Trying to get rails testing working.

The command rake db:test:prepare appears to work fine --

$ rake db:test:prepare -t
(in /home/beau/looked)
** Invoke db:test:prepare (first_time)
** Invoke db:abort_if_pending_migrations (first_time)
** Invoke environment (first_time)
** Execute environment
** Execute db:abort_if_pending_migrations
** Execute db:test:prepare
** Invoke db:test:load (first_time)
** Invoke db:test:purge (first_time)
** Invoke environment 
** Execute db:test:purge
** Execute db:test:load
** Invoke db:schema:load (first_time)
** Invoke environment 
** Execute db:schema:load
NOTICE:  CREATE TABLE will create implicit sequence "slugs_id_seq" for serial column "slugs.id"
NOTICE:  CREATE TABLE / PRIMARY KEY will create implicit index "slugs_pkey" for table "slugs"

BUT some of the tables are not being created.

These are the "development" tables:

$ psql -d looked -U admin -c '\d'

               List of relations
 Schema |       Name        |   Type   | Owner 
--------+-------------------+----------+-------
 public | businesses        | table    | admin
 public | businesses_id_seq | sequence | admin
 public | categories        | table    | admin
 public | categories_id_seq | sequence | admin
 public | schema_migrations | table    | admin
 public | slugs             | table    | admin
 public | slugs_id_seq      | sequence | admin
(7 rows)

Tables created by rake:db:prepare for the test environment --

$ psql -d looked_test -U admin -c '\d'
               List of relations
 Schema |       Name        |   Type   | Owner
--------+-------------------+----------+-------
 public | categories        | table    | admin
 public | schema_migrations | table    | admin
 public | slugs             | table    | admin
 public | slugs_id_seq      | sequence | admin
(4 rows)

As you can see it has created some tables, but not businesses, businesses_id_seq or categories_id_seq.

I'm at a loss as to why, can someone help me?

like image 452
Beau Barker Avatar asked May 03 '11 12:05

Beau Barker


1 Answers

First make sure to run rake db:migrate before rake db:test:prepare.

If that doesn't work, back up your schema.rb somewhere, remove it, then run rake db:schema:dump before running rake db:test:prepare. That will make sure your schema.rb file fully reflects your database.

like image 186
Dylan Markow Avatar answered Oct 07 '22 14:10

Dylan Markow