Skip to content

Instantly share code, notes, and snippets.

@searls
Last active January 23, 2018 13:31
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save searls/eb2e9d25d03709df1debe11394b1454b to your computer and use it in GitHub Desktop.
Save searls/eb2e9d25d03709df1debe11394b1454b to your computer and use it in GitHub Desktop.
It sorta looks like Rails fixtures can't handle joiner tables that have t.timestamps on them
class CreatePostsTags < ActiveRecord::Migration[5.1]
def change
create_table :posts_tags do |t|
t.references :post, foreign_key: true
t.references :tag, foreign_key: true
t.timestamps
end
end
end
hills:
name: hills
author: jack
pails:
name: pails
author: jill
water:
name: water
author: jack
crown:
name: crown
author: jill
tumbling:
name: tumbling
author: jack
caution:
title: Avoid the hill!
body: Turns out, it's really easy to fall down the hill and break your crown
author: jack
tags: hills, crown, tumbling
plumbing:
title: We need water supply
body: It's ridiculous we're still fetching water with a pail, we need plumbing
author: jill
tags: water, pails
$ rake db:drop db:setup db:fixtures:load
Dropped database 'simple-example_development'
Dropped database 'simple-example_test'
Created database 'simple-example_development'
Created database 'simple-example_test'
-- enable_extension("plpgsql")
-> 0.0203s
-- create_table("authors", {:force=>:cascade})
-> 0.0063s
-- create_table("posts", {:force=>:cascade})
-> 0.0098s
-- create_table("posts_tags", {:force=>:cascade})
-> 0.0083s
-- create_table("tags", {:force=>:cascade})
-> 0.0062s
-- add_foreign_key("posts", "authors")
-> 0.0049s
-- add_foreign_key("posts_tags", "posts")
-> 0.0021s
-- add_foreign_key("posts_tags", "tags")
-> 0.0025s
-- add_foreign_key("tags", "authors")
-> 0.0014s
-- enable_extension("plpgsql")
-> 0.0229s
-- create_table("authors", {:force=>:cascade})
-> 0.0050s
-- create_table("posts", {:force=>:cascade})
-> 0.0088s
-- create_table("posts_tags", {:force=>:cascade})
-> 0.0097s
-- create_table("tags", {:force=>:cascade})
-> 0.0076s
-- add_foreign_key("posts", "authors")
-> 0.0030s
-- add_foreign_key("posts_tags", "posts")
-> 0.0018s
-- add_foreign_key("posts_tags", "tags")
-> 0.0017s
-- add_foreign_key("tags", "authors")
-> 0.0013s
rake aborted!
ActiveRecord::NotNullViolation: PG::NotNullViolation: ERROR: null value in column "created_at" violates not-null constraint
DETAIL: Failing row contains (1, 1050461717, 684148082, null, null).
: INSERT INTO "posts_tags" ("post_id", "tag_id") VALUES (1050461717, 684148082)
Caused by:
PG::NotNullViolation: ERROR: null value in column "created_at" violates not-null constraint
DETAIL: Failing row contains (1, 1050461717, 684148082, null, null).
Tasks: TOP => db:fixtures:load
(See full trace by running task with --trace)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment