0

我正在使用 Play 2.3 并尝试通过进化为 PostgreSQL 9.4 生成关系数据库。

我的conf/evolutions/default/1.sql脚本中有以下语句:

ALTER TABLE ONLY round
ADD CONSTRAINT round_event_id_fkey FOREIGN KEY (event_id) REFERENCES event(id);

ALTER TABLE ONLY round
ADD CONSTRAINT round_event_id UNIQUE (event_id);

以下是我的事件表描述:

Table "public.event"
            Column             |            Type             |                     Modifiers
-------------------------------+-----------------------------+----------------------------------------------------  id                            | integer                     | not null default nextval('event_id_seq'::regclass)  related_event_hash          | character varying(45)       |  start_time                    | timestamp without time zone |  end_time                      | timestamp without time zone |  name                          | character varying(45)       |  status                        | character varying(45)       | not null  owner_id                      | bigint                      | not null  venue_id                     | bigint                      |  participation_hash            | character varying(45)       |  number_of_participants        | integer |  number_of_backup_participants | integer                     |  created                       | timestamp without time zone | not null updated                       | timestamp without time zone | not null Indexes:
    "event_pkey" PRIMARY KEY, btree (id)
    "index_event_name" btree (name)
    "index_event_status" btree (status)
    "index_start_time" btree (start_time) Foreign-key constraints:
    "event_owner_id_fkey" FOREIGN KEY (owner_id) REFERENCES person(id)
    "event_venue_id_fkey" FOREIGN KEY (venue_id) REFERENCES venue(id) Referenced by:
    TABLE "anonymous_person" CONSTRAINT "anonymous_person_event_id_fkey" FOREIGN KEY (event_id) REFERENCES event(id)
    TABLE "mix_game" CONSTRAINT "mix_game_event_id_fkey" FOREIGN KEY (event_id) REFERENCES event(id)
    TABLE "participant" CONSTRAINT "participant_event_id_fkey" FOREIGN KEY (event_id) REFERENCES event(id)

当我在浏览器中启动应用程序时,出现此错误:

Database 'default' is in an inconsistent state!

在尝试运行此 SQL 脚本时,我们收到以下错误:

ERROR: there is no unique constraint matching given keys for referenced table "round" [ERROR:0, SQLSTATE:42830] 

有什么问题?如何修复此错误并添加外键约束?

请注意,它在没有外键约束的情况下按如下方式生成数据库轮次。

                                 Table "public.round"


    Column      |         Type          |                     Modifiers
------------------+-----------------------+----------------------------------------------------
 id               | integer               | not null default nextval('round_id_seq'::regclass)
 round_no         | integer               | not null
 event_id         | bigint                | not null
 state            | character varying(20) | not null
 team_composition | character(12)         | not null
 result           | character varying(20) |
 description      | character varying(45) |
 play_time        | integer               | not null
 shift_time       | integer               |
 change_time      | integer               |
Indexes:
    "round_pkey" PRIMARY KEY, btree (id)
    "round_event_id" UNIQUE CONSTRAINT, btree (event_id)
4

1 回答 1

0

看看文档

如您所见,您必须通过在 SQL 脚本中使用注释来分隔 Ups 和 Downs 部分。

另外,不要编辑1.sql文件,因为它是由进化机制更新的。开始您自己的进化2.sql

于 2015-06-06T16:59:09.973 回答