blogo
blogo copied to clipboard
Relation posts does not exist
Hello, I've been through blogo install and i am constantly coming to this error saying that relation posts does not exist when i run * rake db:migrate* COuld you help please?
== 20160330195628 CreateBlogoTaggings: migrating ============================== -- create_table("blogo_taggings") rake aborted! StandardError: An error has occurred, this and all later migrations canceled:
PG::UndefinedTable: ERROR: relation "posts" does not exist : CREATE TABLE "blogo_taggings" ("id" serial primary key, "post_id" integer NOT NULL, "tag_id" integer NOT NULL, CONSTRAINT fk_blogo_taggings_post_id FOREIGN KEY ("post_id") REFERENCES "posts" ("id"), CONSTRAINT fk_blogo_taggings_tag_id FOREIGN KEY ("tag_id") REFERENCES "tags" ("id")) /usr/local/rvm/gems/ruby-2.1.3/gems/activerecord-4.1.5/lib/active_record/connection_adapters/postgresql/database_statements.rb:128:in `async_exec'
Looks strange. At the point when CreateBlogoTaggings is being applied there is not posts
table, and it should be used withing that migration. Can you ensure, that you haven't updated CreateBlogoTaggings manually?
Hello, Thanx for your reply No i haven't I have done exactly as stated on the install guide Help appreciated to sort the issue out Thanx Eric
where should table post ne created? Is it possible to create it manually?
I can't really debug this issue Eruc
Take a look at the migrations: https://github.com/greyblake/blogo/tree/master/db/migrate
Sorry, my bad.. Taggings are created at last. When tags
and posts
are created. Looks like you skipped CreatePosts
migration. Make sure, that you have all these 4 migrations in your app, and they are in the same order.
Hi greyblake,
I have made sure i run the migrations one by one in the orfer provided
Three first migrations run perfectly
blogo_taggings migration return a "relation posts does not exist" error
Why is postgres looking for relation "posts" where it should look for "blogo_posts"?? Probably there is the problem
Thanx
Eric
Looks like problem is hidden here: https://github.com/greyblake/blogo/blob/master/db/migrate/20140218134620_create_blogo_taggings.rb#L14
Can you do rails console
and type:
Blogo.table_name_prefix
Blogo::Post.table_name
What output do you get?
Hello first comment gives "blogo_" second gives "blogo_posts"
Eric
I have changed file db/migrate/20160408210824_create_blogo_taggings.blogo.rb
changing post_id to blogo_post_id and tag_id to blogo_tag_id and it works But why do i have to change this?
class CreateBlogoTaggings < ActiveRecord::Migration def change taggings_table = "#{Blogo.table_name_prefix}taggings"
create_table(taggings_table) do |t|
t.integer :blogo_post_id, null: false
t.integer :blogo_tag_id , null: false
end
add_index taggings_table, [:blogo_tag_id, :blogo_post_id], unique: true
if defined?(Foreigner)
tags_table = "#{Blogo.table_name_prefix}tags"
posts_table = "#{Blogo.table_name_prefix}posts"
add_foreign_key taggings_table, tags_table , column: :blogo_tag_id
add_foreign_key taggings_table, posts_table, column: :blogo_post_id
end
end end
class CreateBlogoTaggings < ActiveRecord::Migration def change taggings_table = "#{Blogo.table_name_prefix}taggings"
create_table(taggings_table) do |t|
t.integer :blogo_post_id, null: false
t.integer :blogo_tag_id , null: false
end
add_index taggings_table, [:blogo_tag_id, :blogo_post_id], unique: true
if defined?(Foreigner)
tags_table = "#{Blogo.table_name_prefix}tags"
posts_table = "#{Blogo.table_name_prefix}posts"
add_foreign_key taggings_table, tags_table , column: :blogo_tag_id
add_foreign_key taggings_table, posts_table, column: :blogo_post_id
end
end end
Now it works
@jengweneg Hi, your solution does fix the issue for migration but it creates another issue when submitting a new post. how did u solve that?