blogo icon indicating copy to clipboard operation
blogo copied to clipboard

Relation posts does not exist

Open jengweneg opened this issue 8 years ago • 9 comments

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'

jengweneg avatar Mar 30 '16 20:03 jengweneg

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?

greyblake avatar Apr 06 '16 11:04 greyblake

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

jengweneg avatar Apr 06 '16 12:04 jengweneg

where should table post ne created? Is it possible to create it manually?

I can't really debug this issue Eruc

jengweneg avatar Apr 06 '16 12:04 jengweneg

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.

greyblake avatar Apr 06 '16 13:04 greyblake

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

jengweneg avatar Apr 08 '16 22:04 jengweneg

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?

greyblake avatar Apr 08 '16 23:04 greyblake

Hello first comment gives "blogo_" second gives "blogo_posts"

Eric

jengweneg avatar Apr 09 '16 10:04 jengweneg

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 avatar Apr 09 '16 10:04 jengweneg

@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?

sushant12 avatar Feb 15 '18 12:02 sushant12