Error connecting spring boot to mysql

0

The error in spring boot is:

  

Error starting ApplicationContext. To display the conditions report re-run your application with 'debug' enabled.   2018-07-14 16: 11: 53,259 ERROR 13188 --- [restartedMain] o.s.boot.SpringApplication: Application run failed

     

org.springframework.beans.factory.BeanCreationException: Error creating bean with name 'flywayInitializer' defined in class path resource [org / springframework / boot / autoconfigure / flyway / FlywayAutoConfiguration $ FlywayConfiguration.class]: Invocation of init method failed; nested exception is org.flywaydb.core.api.FlywayException: Validate failed: Detected failed migration to version 01

     

org.springframework.beans.factory.BeanCreationException: Error creating bean with name 'flywayInitializer' defined in class path resource [org / springframework / boot / autoconfigure / flyway / FlywayAutoConfiguration $ FlywayConfiguration.class]: Invocation of init method failed; nested exception is org.flywaydb.core.api.FlywayException: Validate failed: Detected failed migration to version 01

Code of aplications.proprietes

spring.jpa.hibernate.ddl-auto=none
spring.datasource.url=jdbc:mysql://localhost:3306/banco
spring.datasource.username=root
spring.datasource.password=danilo20

Database code

CREATE DATABASE banco;
USE banco;
CREATE TABLE categoria (
id BIGINT(20) PRIMARY KEY AUTO_INCREMENT,
name VARCHAR(50) NOT NULL
);

INSERT INTO categoria(name) values("Lazer");
INSERT INTO categoria(name) values("Alimentação");
INSERT INTO categoria(name) values("SuperMercado");
INSERT INTO categoria(name) values("Academia");

I even gave a drop table, but it still does not work.

    
asked by anonymous 14.07.2018 / 21:32

1 answer

0

According to the error, you may be having problems with the flyway, however, there are some variants that may be causing this problem, it is up to you to analyze and verify which would be the most relevant to solve your problem. >

1 - You need to add this information in the application.properties:

spring.jpa.database-platform=org.mariadb.jdbc.Driver
spring.jpa.properties.hibernate.dialect=org.hibernate.dialect.MySQL5InnoDBDialect

NOTE: This information is for MariaDB.

2 - If the error persists, there are some versions of MySql that require the url to be written like this:

spring.datasource.url=jdbc:mysql://localhost/nameBase?createDatabaseIfNotExist=true&useSSL=false

3 - Do not forget that the flyway should follow the following rule:

3.1. Migrations should be in the resources / db / migration folder

3.2. And the names should follow the pattern of    V01__criar_e_insere_category.sql

To check your flyway migrations, you can use the following command:

   mvn flyway:info 
    
15.07.2018 / 22:33