Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Play framework 2.2.2 evolutions are not getting fired in mysql

In the sample todo app in play documentation, creating the tasks table using mysql has not been creating evolutions. I tried using

applyEvolutions.default=true

in application.conf . Even tried starting the application with

start -DapplyEvolutions.default=true 

The mysql query was also not a problem, as entering it manually inside mysql console made it work properly. There were no issues with db connection as well, because after creating the table manually, the insert and delete operations were working fine from the application.

for further reference here's application.conf

    # This is the main configuration file for the application.
# ~~~~~

# Secret key
# ~~~~~
# The secret key is used to secure cryptographics functions.
# If you deploy your application to several instances be sure to use the same key!
application.secret="PwleF1NyxkZ[8Oq`j`^NMg:6Vu6MMiHv?s:Ff>3@VpiKfA^9qSvb/E_>5[BRq>h6"

# The application languages
# ~~~~~
application.langs="en"

# Global object class
# ~~~~~
# Define the Global object class for this application.
# Default to Global in the root package.
# application.global=Global

# Router
# ~~~~~
# Define the Router object to use for this application.
# This router will be looked up first when the application is starting up,
# so make sure this is the entry point.
# Furthermore, it's assumed your route file is named properly.
# So for an application router like `my.application.Router`,
# you may need to define a router file `conf/my.application.routes`.
# Default to Routes in the root package (and conf/routes)
# application.router=my.application.Routes

# Database configuration
# ~~~~~
# You can declare as many datasources as you want.
# By convention, the default datasource is named `default`
#
# db.default.driver=org.h2.Driver
# db.default.url="jdbc:h2:mem:play"
# db.default.user=sa
# db.default.password=""

# Evolutions
# ~~~~~
# You can disable evolutions if needed
# evolutionplugin=disabled
applyEvolutions.default=true

DapplyDownEvolutions.default=true

# Logger
# ~~~~~
# You can also configure logback (http://logback.qos.ch/),
# by providing an application-logger.xml file in the conf directory.

# Root logger:
logger.root=ERROR

# Logger used by the framework:
logger.play=INFO

# Logger provided to your application:
logger.application=DEBUG

db.default.driver=com.mysql.jdbc.Driver
db.default.url="jdbc:mysql://localhost/sql_test"
db.default.user="testuser"
db.default.pass=""

and here is 1.sql

# Tasks schema

# --- !Ups

CREATE TABLE task (
    id int NOT NULL AUTO_INCREMENT,
    label varchar(255),
    PRIMARY KEY (ID)
);

# --- !Downs


DROP TABLE task;
like image 932
Ranjith Kumar Avatar asked Dec 20 '22 17:12

Ranjith Kumar


2 Answers

Check the following:

Your evolution files (1.sql, 2.sql, etc) should be in the conf/evolutions/default/ directory, where default is the name you've given your database in application.conf. By this I mean

db.default.driver=com.mysql.jdbc.Driver
db.default.url="jdbc:mysql://localhost/sql_test"
db.default.user="testuser"
db.default.pass=""

Next, check that you've set up and down evolutions to be automatically applied in your application.conf and evolutionplugin is set to enabled

evolutionplugin=enabled
applyEvolutions.default=true
applyDownEvolutions.default=true

Note: you have DapplyDownEvolutions in your application.conf

Besides your app's configuration there are some other things to check:

  1. Do the login credentials you've supplied work?
  2. Are there any tables in the target database? I would make sure all tables are wiped from it including play_evolutions.
  3. Try creating the schema manually with 'testuser', perhaps the login does not have permission to use CREATE

Hopefully that helps.

like image 154
Jason Pearson Avatar answered Jan 14 '23 00:01

Jason Pearson


Additionally, make sure you have

libraryDependencies += evolutions

in your build.sbt, since it has become an external module.

More on evolutions: Link

like image 44
Matthias Braun Avatar answered Jan 14 '23 01:01

Matthias Braun