Skip to content
This repository has been archived by the owner on May 13, 2022. It is now read-only.

Unable to disable automatic foreign key constraints #148

Open
mhuggins opened this issue Mar 16, 2014 · 0 comments
Open

Unable to disable automatic foreign key constraints #148

mhuggins opened this issue Mar 16, 2014 · 0 comments

Comments

@mhuggins
Copy link

Hi there! I'm trying to use schema_plus on a new rails project from scratch. I see references to disabling automatic foreign key creation, but it doesn't seem to be working for me. I'm using schema_plus 1.4.1 with PostgreSQL.

My config/initializers/schema_plus.rb contains:

SchemaPlus.setup do |config|
  config.foreign_keys.auto_create = false
end

My migration file is essentially:

create_table :champions do |t|
  t.string :api_id, null: false, index: { unique: true }
  # ...other columns...

  t.timestamps
end

Running bundle exec rake db:migrate results in:

== 20140315224008 CreateChampions: migrating ==================================
-- create_table(:champions)
rake aborted!
An error has occurred, this and all later migrations canceled:

PG::UndefinedTable: ERROR:  relation "apis" does not exist
: CREATE TABLE "champions" ("id" serial primary key, "api_id" character varying(255) NOT NULL, "name" character varying(255) NOT NULL, "title" character varying(255) NOT NULL, "image" character varying(255) NOT NULL, "attack_rank" integer NOT NULL, "defense_rank" integer NOT NULL, "magic_rank" integer NOT NULL, "difficulty_rank" integer NOT NULL, "created_at" timestamp, "updated_at" timestamp, CONSTRAINT fk_champions_api_id FOREIGN KEY ("api_id") REFERENCES "apis" ("id"))

Any idea why the FK option is not disabled despite my attempt to explicitly disable?

Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant