Search code examples
ruby-on-railssqliterails-migrationsseeding

Cannot find table in Ruby Migration


I'm trying to seed a Ruby SQLite3 database with the following commands.

SubmissionPool.create(
[ { submission_pool_id: "5769bdf9-ac24-4b4c-bc35-6062de526285", submission_pool_description: "images", created_at: Time.new , updated_at: Time.new  }
])

Submission.create(
[ { submission_ID: "ff336040-d5e7-4c80-a0b8-53d2204bd027", submission_title: "TestSubmission",  submission_description: "TestSubmission",
  submission_file: "http://www.joomlaworks.net/images/demos/galleries/abstract/7.jpg", created_by: "00000000-0000-0000-0000-000000000000", created_at: Time.new , updated_at: Time.new  }
])

And it keeps giving me the error that table Submissions is not found. So far I've been creating the models with the rails generate model command and it has all worked out.

I tried

  • Dropping the table and recreating it.
  • Deleting the entire database and re migrating it.
  • Tried various different caps letters (i know stupid but hey)

Now I've read somewhere that sqlite 3 isn't that good with plurals in the table name. Could any of you give me a pointer in the right direction. I'll attach my migration code and model code below.

submission.rb

class Submission < ActiveRecord::Base
end

Migration

class CreateSubmissions < ActiveRecord::Migration
  def change
    create_table :submission, :id => false do |t|
      t.uuid :submission_ID, :primary_key => true, null: false
      t.string :submission_title, null: false
      t.text :submission_description, null: false
      t.string :submission_file, null: false
      t.datetime :created_on, null: false
      t.uuid :created_by, null: false

       t.timestamps null: false
    end
  end
end

Solution

  • Here you create table submission:

    create_table :submission, :id => false do |t|
      ...
    end
    

    Your error is caused by this name. Rails expects Submission model's table to be submissions.

    You can still use this name, but it should be explicitly be declared in Submission model:

    class Submission < ActiveRecord::Base
      self.table_name :submission
    end