I am getting the following error ActiveRecord::Fixture::FixtureError: table "customers_database_configs" has no columns named "customers_database_cluster". when I try rails db:fixtures:load. I believe it is due to the name-spacing of the models but I can't for the life of me figure out how to fix the issue. Using Rails 6.1.5.1, I have included the relevant files below including schema, migrations, models and fixtures.
Below is the relevant part of the schema:
create_table "customers_database_configs", force: :cascade do |t|
t.string "hostname"
t.integer "port"
t.string "database"
t.string "schema"
t.string "db_username"
t.string "db_password"
t.boolean "active"
t.datetime "valid_until"
t.boolean "refresh_database"
t.string "storage_bucket"
t.string "storage_username"
t.string "storage_password"
t.string "timezone"
t.json "data"
t.string "account_uid"
t.bigint "customers_database_cluster_id"
t.datetime "created_at", precision: 6, null: false
t.datetime "updated_at", precision: 6, null: false
t.index ["customers_database_cluster_id"], name: "customers_database_cluster_id"
end
Below is the relevant part of the migrations:
class CreateCustomersDatabaseClusters < ActiveRecord::Migration[6.1]
def change
create_table :customers_database_clusters do |t|
t.string :hostname
t.integer :port
t.string :database
t.string :su_username
t.string :su_password
t.timestamps
end
end
end
class CreateCustomersDatabaseConfigs < ActiveRecord::Migration[6.1]
def change
create_table :customers_database_configs do |t|
t.string :account_uid
t.integer :port
t.string :database
t.string :schema
t.string :db_username
t.string :db_password
t.boolean :active
t.datetime :valid_until
t.boolean :refresh_database
t.string :storage_bucket
t.string :storage_username
t.string :storage_password
t.string :timezone
t.json :data
t.string :account_uid
t.references :customers_database_cluster, index: { name: :customers_database_cluster_id }
t.timestamps
end
end
end
Below is the relevant part of the models:
#app/models/customers_database/config.rb
module CustomersDatabase
class Config < ApplicationRecord
belongs_to :cluster
end
end
#app/models/customers_database/cluster.rb
module CustomersDatabase
class Cluster < ApplicationRecord
has_many :configs
end
end
#app/models/customers_database.rb
module CustomersDatabase
def self.table_name_prefix
'customers_database_'
end
end
and fixtures:
#test/fixtures/customers_database/clusters.yml
# Read about fixtures at https://api.rubyonrails.org/classes/ActiveRecord/FixtureSet.html
one:
port: 1
hostname: MyString
database: MyString
su_username: MyString
su_password: MyString
two:
port: 1
hostname: MyString
database: MyString
su_username: MyString
su_password: MyString
#test/fixtures/customers_database/configs.yml
# Read about fixtures at https://api.rubyonrails.org/classes/ActiveRecord/FixtureSet.html
one:
hostname: MyString
port: 1
database: MyString
schema: MyString
db_username: MyString
db_password: MyString
active: false
valid_until: 2022-05-23 17:21:17
refresh_database: false
storage_bucket: MyString
storage_username: MyString
storage_password: MyString
timezone: MyString
data:
customers_database_cluster: one
two:
hostname: MyString
port: 1
database: MyString
schema: MyString
db_username: MyString
db_password: MyString
active: false
valid_until: 2022-05-23 17:21:17
refresh_database: false
storage_bucket: MyString
storage_username: MyString
storage_password: MyString
timezone: MyString
data:
customers_database_cluster: two