为什么Play Framework中的进化不起作用?

时间:2015-06-05 12:23:36

标签: postgresql playframework-2.3 playframework-evolutions

我正在使用Play 2.3并试图通过Evolution为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)

1 个答案:

答案 0 :(得分:0)

查看documentation

  

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

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