5
respostas

[Dúvida] Erro migration v4

Meu migration v4__create_table_resposta.sql está dando erro e eu não faço ideia do motivo. O resultado do log é este: 2022-10-25 22:45:03.494 INFO 35241 --- [ restartedMain] o.f.core.internal.command.DbMigrate : Migrating schema "PUBLIC" to version "4 - create table resposta" 2022-10-25 22:45:03.496 ERROR 35241 --- [ restartedMain] o.f.core.internal.command.DbMigrate : Migration of schema "PUBLIC" to version "4 - create table resposta" failed! Please restore backups and roll back database and code!

2022-10-25 22:45:03.499 WARN 35241 --- [ restartedMain] ConfigServletWebServerApplicationContext : Exception encountered during context initialization - cancelling refresh attempt: 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.internal.command.DbMigrate$FlywayMigrateException: Migration V4__create_table_resposta.sql failed

SQL State : 42001 Error Code : 42001 Message : Syntax error in SQL statement "create table resposta(\000a id bigint not null,\000a mensagem varchar(400) not null,\000a datacriacao datetime not null,\000a autor_id bigint not null,\000a topico_id bigint not null,\000a solucao int* not null,\000a primary key(id),\000a foreign key(topico_id) REFERENCES topico(id),\000a foreign key(autor_id) REFERENCES usuario(id)\000a)"; expected "ARRAY, INVISIBLE, VISIBLE, NOT NULL, NULL, AS, DEFAULT, GENERATED, ON UPDATE, NOT NULL, NULL, AUTO_INCREMENT, DEFAULT ON NULL, NULL_TO_DEFAULT, SEQUENCE, SELECTIVITY, COMMENT, CONSTRAINT, COMMENT, PRIMARY KEY, UNIQUE, NOT NULL, NULL, CHECK, REFERENCES, AUTO_INCREMENT, ,, )"; SQL statement: create table resposta( id bigint not null, mensagem varchar(400) not null, datacriacao datetime not null, autor_id bigint not null, topico_id bigint not null, solucao int(1) not null, primary key(id), foreign key(topico_id) REFERENCES topico(id), foreign key(autor_id) REFERENCES usuario(id) ) [42001-214] Location : db/migration/V4__create_table_resposta.sql (/home/mauricio/Documents/Git/courseware-content/Alura/Kotlin/Kotlin Spring_Boot/forum/target/classes/db/migration/V4__create_table_resposta.sql) Line : 1 Statement : create table resposta( id bigint not null, mensagem varchar(400) not null, datacriacao datetime not null, autor_id bigint not null, topico_id bigint not null, solucao int(1) not null, primary key(id), foreign key(topico_id) REFERENCES topico(id), foreign key(autor_id) REFERENCES usuario(id) )

5 respostas

o conteúdo do migration é igual ao especificado no curso:

create table resposta( id bigint not null, mensagem varchar(400) not null, datacriacao datetime not null, autor_id bigint not null, topico_id bigint not null, solucao int(1) not null, primary key(id), foreign key(topico_id) REFERENCES topico(id), foreign key(autor_id) REFERENCES usuario(id) );

Oi Mauricio,

Aparentemente está cerintho mesmo a migration.

Qual banco de dados você está utilizando no seu projeto? Posta aqui também o código das suas outras migrations.

Estou utilizandoo H2 mesmo, assim como ensinado no curso. É meu primeiro contato, então estou tentando seguir à risca. Tentei algumas coisas mas continua dando erro. :/

Edit: Continua dando erro. :(

Inclusive, se puder dar uma olhada no meu código no github, eu agradeceria. Eu realmente tô sem saber o que fazer por aqui.

https://github.com/mauriciodesm/courseware-content/tree/main/Alura/Kotlin/Kotlin%2BSpring_Boot/forum

Tenta substituir o int(1) por bit, estava como mesmo problema, e agora foi.

create table resposta( id bigint not null, mensagem varchar(300) not null, data_criacao datetime not null, topico_id bigint not null, autor_id bigint not null, solucao bit not null, primary key(id), foreign key(topico_id) references topico(id), foreign key(autor_id) references usuario(id) );

Quer mergulhar em tecnologia e aprendizagem?

Receba a newsletter que o nosso CEO escreve pessoalmente, com insights do mercado de trabalho, ciência e desenvolvimento de software