Auf Migration bekomme ich folgende Fehlermeldung:PG :: UndefinedTable: ERROR: Beziehung "..." existiert nicht
PG::UndefinedTable: ERROR: relation "actioncodes" does not exist
: ALTER TABLE "organizations" ADD CONSTRAINT "fk_rails_4ecaa2493e"
FOREIGN KEY ("actioncode_id")
REFERENCES "actioncodes" ("id")
Ich habe folgende Migrationsdatei für Organisationen:
class CreateOrganizations < ActiveRecord::Migration
def change
create_table :organizations do |t|
t.string :name, null: false, limit: 40
t.references :actioncode, index: true, foreign_key: true
t.boolean :activated
t.datetime :activated_at
t.timestamps null: false
end
end
end
Und für Actioncodes habe ich die Migrationsdatei:
class CreateActioncodes < ActiveRecord::Migration
def change
create_table :actioncodes do |t|
t.string :code, null: false, limit: 20
t.string :description, limit: 255
t.timestamps null: false
end
end
end
class AddIndexToActioncodesCode < ActiveRecord::Migration
def change
add_index :actioncodes, :code, unique: true
end
end
Das Organisationsmodell-Datei enthält: belongs_to :actioncode
.
Während die Actioncode-Modelldatei enthält: has_many :organizations
.
Irgendeine Idee, was die Fehlermeldung verursachen könnte?
Wenn ich index: true, foreign_key: true
aus der Migrationsdatei entferne, migriert es ohne Fehler. Und wenn ich diese Zeile mit der falschen Zeile t.references :actioncode_id, index: true, foreign_key: true
ersetze, gibt es den Fehler unten, wo die letzte Zeile ("IDs") schlägt vor, dass Schienen irgendwie Problem mit dem Namen der Tabelle hat?
PG::UndefinedTable: ERROR: relation "actioncode_ids" does not exist
: ALTER TABLE "organizations" ADD CONSTRAINT "fk_rails_604f95d1a1"
FOREIGN KEY ("actioncode_id_id")
REFERENCES "actioncode_ids" ("id")
Der Tabellenname ist Actioncodes. Ich habe seine Migrationsdatei zum ursprünglichen Beitrag hinzugefügt – Nick
Sieht so aus, als ob die 'CreateOrganizations'-Migration ausgeführt wird, bevor' CreateActioncodes' ausgeführt wird. - 'CreateActioncodes' soll zuerst ausgeführt werden, um sicherzustellen, dass die' actioncodes' Tabelle existiert. –
Kannst du mir vielleicht raten, wie ich das ändern soll? Ich habe überprüft und der SQL-Code bestätigt tatsächlich, dass Organisationen vor Actioncodes erstellt werden. – Nick