spring 在部署过程中,它会抛出一个错误:关系“usr”不存在

hgqdbh6s  于 2023-08-02  发布在  Spring
关注(0)|答案(1)|浏览(106)

这是我第一次做部署,我意识到了迁移的问题。

2023-08-01T20:10:30.302+03:00 ERROR 6477 --- [           main] o.s.b.web.embedded.tomcat.TomcatStarter  : Error starting Tomcat context. Exception: org.springframework.beans.factory.UnsatisfiedDependencyException. Message: Error creating bean with name 'sessionRepositoryFilterRegistration' defined in class path resource [org/springframework/boot/autoconfigure/session/SessionRepositoryFilterConfiguration.class]: Unsatisfied dependency expressed through method 'sessionRepositoryFilterRegistration' parameter 1: Error creating bean with name 'springSessionRepositoryFilter' defined in class path resource [org/springframework/session/config/annotation/web/http/SpringHttpSessionConfiguration.class]: Unsatisfied dependency expressed through method 'springSessionRepositoryFilter' parameter 0: Error creating bean with name 'flywayInitializer' defined in class path resource [org/springframework/boot/autoconfigure/flyway/FlywayAutoConfiguration$FlywayConfiguration.class]: Migration V2__Add_admin.sql failed
    ----------------------------------
    SQL State  : 42P01
    Error Code : 0
    Message    : ERROR: relation "usr" does not exist
      Position: 13
    Location   : db/migration/V2__Add_admin.sql (/root/file:/root/sellmagazin-0.0.1-SNAPSHOT.jar!/BOOT-INF/classes!/db/migration/V2__Add_admin.sql)
    2023-08-01T20:10:31.035+03:00 ERROR 6477 --- [           main] o.s.boot.SpringApplication               : Application run failed
    
    org.springframework.context.ApplicationContextException: Unable to start web server
            at org.springframework.boot.web.servlet.context.ServletWebServerApplicationContext.onRefresh(ServletWebServerApplicationContext.java:164) ~[spring-boot-3.0.5.jar!/:3.0.5]
            at org.springframework.context.support.AbstractApplicationContext.refresh(AbstractApplicationContext.java:578) ~[spring-context-6.0.7.jar!/:6.0.7]
    
    Caused by: org.springframework.beans.factory.UnsatisfiedDependencyException: Error creating bean with name 'sessionRepositoryFilterRegistration' defined in class path resource [org/springframework/boot/autoconfigure/session/SessionRepositoryFilterConfiguration.class]: Unsatisfied dependency expressed through method 'sessionRepositoryFilterRegistration' parameter 1: Error creating bean with name 'springSessionRepositoryFilter' defined in class path resource [org/springframework/session/config/annotation/web/http/SpringHttpSessionConfiguration.class]: Unsatisfied dependency expressed through method 'springSessionRepositoryFilter' parameter 0: Error creating bean with name 'flywayInitializer' defined in class path resource [org/springframework/boot/autoconfigure/flyway/FlywayAutoConfiguration$FlywayConfiguration.class]: Migration V2__Add_admin.sql failed
    ----------------------------------
    SQL State  : 42P01
    Error Code : 0
    Message    : ERROR: relation "usr" does not exist
      Position: 13
    Location   : db/migration/V2__Add_admin.sql (/root/file:/root/sellmagazin-0.0.1-SNAPSHOT.jar!/BOOT-INF/classes!/db/migration/V2__Add_admin.sql)
    
    Caused by: org.flywaydb.core.internal.command.DbMigrate$FlywayMigrateException: Migration V2__Add_admin.sql failed
    ----------------------------------
    SQL State  : 42P01
    Error Code : 0
    Message    : ERROR: relation "usr" does not exist
      Position: 13
    Location   : db/migration/V2__Add_admin.sql (/root/file:/root/sellmagazin-0.0.1-SNAPSHOT.jar!/BOOT-INF/classes!/db/migration/V2__Add_admin.sql)

字符串
V2__Add_admin

insert into usr (id, username, password, active)
    values (1, 'admin', '123', true);
    
    insert into user_role (user_id, roles)
    values (1, 'USER'), (1, 'ADMIN');
    
    
    insert into usr (id, username, password, active)
    values (2, 'admin2', '123', true);
    
    insert into user_role (user_id, roles)
    values (2, 'USER'), (2, 'ADMIN');


的数据



我在windows上工作,也许只要数据库形成就不会了?改变位置,即先db,再迁移,没有帮助
V1__Init_DB文件内容如下:

create sequence hibernate_sequence start 1 increment 1;
    
    create table message (
                             id int8 not null,
                             filename varchar(255),
                             tag varchar(255),
                             text varchar(2048) not null,
                             user_id int8,
                             primary key (id)
    );
    
    create table user_role (
                               user_id int8 not null,
                               roles varchar(255)
    );
    
    create table usr (
                         id int8 not null,
                         activation_code varchar(255),
                         active boolean not null,
                         email varchar(255),
                         password varchar(255) not null,
                         username varchar(255) not null,
                         primary key (id)
    );
    
    alter table if exists message
        add constraint message_user_fk
        foreign key (user_id) references usr;
    
    alter table if exists user_role
        add constraint user_role_user_fk
        foreign key (user_id) references usr;

5n0oy7gb

5n0oy7gb1#

V1__Init_DB文件似乎未通过迁移进行选择。什么是V1__Init_DB文件的扩展名?它是V1__Init_DB.sql还是V1_Init_DB.txt?

相关问题