在将 @ManyToMany 连接表添加到两个模型(在本例中为 User 和 Article 模型[1])时,Play 正确检测到这些更改并相应地修改 1.sql[2] 文件:
[1]
+ @ManyToMany
+ public List<User> authors;
+ @ManyToMany(mappedBy="authors")
+ public List<Article> authoredArticles;
[2]
+ create table articles_users (
+ articles_id bigint not null,
+ users_id bigint not null,
+ constraint pk_articles_users primary key (articles_id, users_id)
+ );
+ alter table articles_users add constraint fk_articles_users_articles_01 foreign key (articles_id) references articles (id);
+ alter table articles_users add constraint fk_articles_users_users_02 foreign key (users_id) references users (id);
# --- !Downs
+ drop table if exists articles_users cascade;
但是,当打开使用此关系的页面时,不会显示有关需要应用 Evolutions 的消息,而是显示以下错误:
PersistenceException: Query threw SQLException:ERROR: relation "articles_users" does not exist
为什么 Play 没有检测到它对需要应用的数据库模式进行了更改?