Rails 4.2 engine reference column migration fails PG::UndefinedTable: ERROR: in postgresql -


in engine have built, have 3 classes: books, categories , authors. migrations each of classes below. there 1 many relationship between authors , books , between categories , books. engine namespaces each of classes book_store. when using same migrations on postgresql (instead of sqlite) error 1 of classes not exist pg::undefinedtable: error: relation "authors" not exist

i'm not sure why error occurring. should namespace in reference well? e.g, this:

  t.references :author, index: true, foreign_key: true   t.references :category, index: true, foreign_key: true 

to this:

  t.references :book_store_author, index: true, foreign_key: true   t.references :book_store_category, index: true, foreign_key: true 

this seems not work because there attribute in bookstore::books named book_store_author , book_store_category resulting in bookstore::books.book_store_author not scoped engine properly.

is possible need change migration code reflect namespace of engine on separate line?

original code

authors

# migration comes book_store (originally 20150814153615) class createbookstoreauthors < activerecord::migration   def change     create_table :book_store_authors |t|       t.string :name       t.text :description       t.string :slug        t.timestamps null: false     end     add_index :book_store_authors, :slug, unique: true   end end 

categories

# migration comes book_store (originally 20150814153710) class createbookstorecategories < activerecord::migration   def change     create_table :book_store_categories |t|       t.string :title       t.text :description       t.string :slug        t.timestamps null: false     end     add_index :book_store_categories, :slug, unique: true   end end 

books

# migration comes book_store (originally 20150814153733) class createbookstorebooks < activerecord::migration   def change     create_table :book_store_books |t|       t.string :title       t.string :lead       t.text :excerpt       t.text :description       t.decimal :price       t.integer :cover_type       t.integer :num_pages       t.string :isbn       t.integer :year       t.string :buy_link       t.string :size       t.string :cover_image       t.string :slug       t.references :author, index: true, foreign_key: true       t.references :category, index: true, foreign_key: true        t.timestamps null: false     end     add_index :book_store_books, :slug, unique: true   end end 

error:

/home/deploy/apps/saturnalia_books/shared/bundle/ruby/2.2.0/gems/activerecord-4.2.3/lib/active_record/migration.rb:797:in `migrate' /home/deploy/apps/saturnalia_books/shared/bundle/ruby/2.2.0/gems/activerecord-4.2.3/lib/active_record/tasks/database_tasks.rb:137:in `migrate' /home/deploy/apps/saturnalia_books/shared/bundle/ruby/2.2.0/gems/activerecord-4.2.3/lib/active_record/railties/databases.rake:44:in `block (2 levels) in <top (required)>' activerecord::statementinvalid: pg::undefinedtable: error:  relation "authors" not exist : alter table "book_store_books" add constraint "fk_rails_52f80cb3c5" foreign key ("author_id")   references "authors" ("id") /home/deploy/apps/saturnalia_books/shared/bundle/ruby/2.2.0/gems/activerecord-4.2.3/lib/active_record/connection_adapters/postgresql/database_statements.rb:155:in `async_exec' /home/deploy/apps/saturnalia_books/shared/bundle/ruby/2.2.0/gems/activerecord-4.2.3/lib/active_record/connection_adapters/postgresql/database_statements.rb:155:in `block in execute'      ...    pg::undefinedtable: error:  relation "authors" not exist 

edit

here full stack trace

you getting pg::undefinedtable, table author trying reference can't found psql. , couldn't found because table named book_store_authors here create_table :book_store_authors. i'm not sure why working on sqlite, need pass full , valid table name creating model (i mean in singular form if user or in plural if in reason creating users model) t.belongs_to , t.references


Comments

Popular posts from this blog

c# - Binding a comma separated list to a List<int> in asp.net web api -

Delphi 7 and decode UTF-8 base64 -

html - Is there any way to exclude a single element from the style? (Bootstrap) -