I''m having problems loading fixtures for a table that will
acts_as_tree.
Macintosh OS X
Rails 0.13.1
Pg 8.0.3
tmornini$ rake test_units
(in /Users/tmornini/Sites/sofarails)
ruby -Ilib:test "/usr/lib/ruby/gems/1.8/gems/rake-0.5.4/lib/rake/
rake_test_loader.rb" "test/unit/category_test.rb"
"test/unit/
credit_card_test.rb" "test/unit/event_test.rb" "test/unit/
ledger_test.rb" "test/unit/photo_test.rb"
"test/unit/proxy_test.rb"
"test/unit/rating_test.rb" "test/unit/seller_test.rb"
"test/unit/
unit_test.rb" "test/unit/user_test.rb"
Loaded suite /usr/lib/ruby/gems/1.8/gems/rake-0.5.4/lib/rake/
rake_test_loader
Started
E........
Finished in 1.652765 seconds.
1) Error:
test_truth(CategoryTest):
ActiveRecord::StatementInvalid: ERROR: insert or update on table
"categories" violates foreign key constraint
"categories_categories"
DETAIL: Key (parent_id)=(1) is not present in table "categories".
: INSERT INTO categories ("name", "allows_sellers",
"id",
"parent_id") VALUES (''Business'',
''t'', 2, 1)
/usr/lib/ruby/gems/1.8/gems/activerecord-1.11.1/lib/
active_record/connection_adapters/abstract_adapter.rb:462:in `log''
/usr/lib/ruby/gems/1.8/gems/activerecord-1.11.1/lib/
active_record/connection_adapters/postgresql_adapter.rb:109:in
`execute''
/usr/lib/ruby/gems/1.8/gems/activerecord-1.11.1/lib/
active_record/fixtures.rb:279:in `insert_fixtures''
/usr/lib/ruby/gems/1.8/gems/activerecord-1.11.1/lib/
active_record/fixtures.rb:278:in `each''
/usr/lib/ruby/gems/1.8/gems/activerecord-1.11.1/lib/
active_record/fixtures.rb:278:in `insert_fixtures''
/usr/lib/ruby/gems/1.8/gems/activerecord-1.11.1/lib/
active_record/fixtures.rb:237:in `create_fixtures''
/usr/lib/ruby/gems/1.8/gems/activerecord-1.11.1/lib/
active_record/fixtures.rb:237:in `each''
/usr/lib/ruby/gems/1.8/gems/activerecord-1.11.1/lib/
active_record/fixtures.rb:237:in `create_fixtures''
/usr/lib/ruby/gems/1.8/gems/activerecord-1.11.1/lib/
active_record/fixtures.rb:235:in `transaction''
/usr/lib/ruby/gems/1.8/gems/activerecord-1.11.1/lib/
active_record/fixtures.rb:235:in `create_fixtures''
/usr/lib/ruby/gems/1.8/gems/activerecord-1.11.1/lib/
active_record/fixtures.rb:522:in `load_fixtures''
/usr/lib/ruby/gems/1.8/gems/activerecord-1.11.1/lib/
active_record/fixtures.rb:479:in `setup_with_fixtures''
/usr/lib/ruby/gems/1.8/gems/activerecord-1.11.1/lib/
active_record/fixtures.rb:504:in `setup''
/usr/lib/ruby/gems/1.8/gems/activerecord-1.11.1/lib/
active_record/fixtures.rb:503:in `setup''
Fixture:
root_category:
id: 1
allows_sellers: ''f''
name: root
parent_id:
business_category:
id: 2
allows_sellers: ''t''
name: Business
parent_id: 1
DB definition:
CREATE TABLE categories (
id SERIAL NOT NULL,
allows_sellers BOOL NOT NULL,
name VARCHAR(80) NOT NULL CONSTRAINT UC_categories_name UNIQUE,
created_at TIMESTAMP DEFAULT LOCALTIMESTAMP NOT NULL,
updated_at TIMESTAMP DEFAULT LOCALTIMESTAMP NOT NULL,
parent_id INT4,
CONSTRAINT PK_categories PRIMARY KEY (id)
);
ALTER TABLE categories
ADD CONSTRAINT categories_categories FOREIGN KEY (parent_id)
REFERENCES categories (id);
Any ideas? How is it possible that id = 1 doesn''t get loaded first?
--
-- Tom Mornini