Reputation: 1453
On adding a @ManyToMany join table to two models, in this case User and Article models[1], Play correctly detects these changes and modifies the 1.sql[2] file accordingly:
[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;
However when opening a page that uses this relationship, no message is displayed about Evolutions needing applying, instead the following error is presented:
PersistenceException: Query threw SQLException:ERROR: relation "articles_users" does not exist
Why is Play not detecting that it has made changes to the database schema that need to be applied?
Upvotes: 2
Views: 1378
Reputation: 1493
Check the play_evolutions table, if there is already a row with id 1 you have to rename the sql file to 2.sql or drop the tables manually.
Upvotes: 2