Spring Boot迁移错误-默认值

时间:2019-02-19 10:09:41

标签: java mysql spring migration default

我无法为该列提供默认值。

    @Id  
    @GeneratedValue(strategy = GenerationType.IDENTITY)  
    private int id;  
    @Column(nullable = false)  
    @org.hibernate.annotations.ColumnDefault("poxos")  
    private String name;  

我还尝试了以下方法:
@Column(nullable = false,columnDefinition = "default 'poxos'")
 private String name;

我收到以下错误。

  

org.hibernate.tool.schema.spi.CommandAcceptanceException:执行DDL错误“通过JDBC语句       在org.hibernate.tool.schema.internal.exec.GenerationTargetToDatabase.accept(GenerationTargetToDatabase.java:67)〜[hibernate-core-5.3.7.Final.jar:5.3.7.Final]       在org.hibernate.tool.schema.internal.SchemaCreatorImpl.applySqlString(SchemaCreatorImpl.java:440)上[hibernate-core-5.3.7.Final.jar:5.3.7.Final]       在org.hibernate.tool.schema.internal.SchemaCreatorImpl.applySqlStrings(SchemaCreatorImpl.java:424)上[hibernate-core-5.3.7.Final.jar:5.3.7.Final]       在org.hibernate.tool.schema.internal.SchemaCreatorImpl.createFromMetadata(SchemaCreatorImpl.java:315)[hibernate-core-5.3.7.Final.jar:5.3.7.Final]       在org.hibernate.tool.schema.internal.SchemaCreatorImpl.performCreation(SchemaCreatorImpl.java:166)上[hibernate-core-5.3.7.Final.jar:5.3.7.Final]       在org.hibernate.tool.schema.internal.SchemaCreatorImpl.doCreation(SchemaCreatorImpl.java:135)上[hibernate-core-5.3.7.Final.jar:5.3.7.Final]       在org.hibernate.tool.schema.internal.SchemaCreatorImpl.doCreation(SchemaCreatorImpl.java:121)上[hibernate-core-5.3.7.Final.jar:5.3.7.Final]       在org.hibernate.tool.schema.spi.SchemaManagementToolCoordinator.performDatabaseAction(SchemaManagementToolCoordinator.java:155)上[hibernate-core-5.3.7.Final.jar:5.3.7.Final]       在org.hibernate.tool.schema.spi.SchemaManagementToolCoordinator.process(SchemaManagementToolCoordinator.java:72)上[hibernate-core-5.3.7.Final.jar:5.3.7.Final]       在org.hibernate.internal.SessionFactoryImpl。(SessionFactoryImpl.java:310)[hibernate-core-5.3.7.Final.jar:5.3.7.Final]       在org.hibernate.boot.internal.SessionFactoryBuilderImpl.build(SessionFactoryBuilderImpl.java:467)上[hibernate-core-5.3.7.Final.jar:5.3.7.Final]       在org.hibernate.jpa.boot.internal.EntityManagerFactoryBuilderImpl.build(EntityManagerFactoryBuilderImpl.java:939)上[hibernate-core-5.3.7.Final.jar:5.3.7.Final]       在org.springframework.orm.jpa.vendor.SpringHibernateJpaPersistenceProvider.createContainerEntityManagerFactory(SpringHibernateJpaPersistenceProvider.java:57)[spring-orm-5.1.5.RELEASE.jar:5.1.5.RELEASE]       在org.springframework.orm.jpa.LocalContainerEntityManagerFactoryBean.createNativeEntityManagerFactory(LocalContainerEntityManagerFactoryBean.java:365)上[spring-orm-5.1.5.RELEASE.jar:5.1.5.RELEASE]       在org.springframework.orm.jpa.AbstractEntityManagerFactoryBean.buildNativeEntityManagerFactory(AbstractEntityManagerFactoryBean.java:390)[spring-orm-5.1.5.RELEASE.jar:5.1.5.RELEASE]       在org.springframework.orm.jpa.AbstractEntityManagerFactoryBean.afterPropertiesSet(AbstractEntityManagerFactoryBean.java:377)[spring-orm-5.1.5.RELEASE.jar:5.1.5.RELEASE]       在org.springframework.orm.jpa.LocalContainerEntityManagerFactoryBean.afterPropertiesSet(LocalContainerEntityManagerFactoryBean.java:341)[spring-orm-5.1.5.RELEASE.jar:5.1.5.RELEASE]       在org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.invokeInitMethods(AbstractAutowireCapableBeanFactory.java:1821)[spring-beans-5.1.5.RELEASE.jar:5.1.5.RELEASE]       在org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.initializeBean(AbstractAutowireCapableBeanFactory.java:1758)上[spring-beans-5.1.5.RELEASE.jar:5.1.5.RELEASE]       在org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.doCreateBean(AbstractAutowireCapableBeanFactory.java:593)[spring-beans-5.1.5.RELEASE.jar:5.1.5.RELEASE]       在org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.createBean(AbstractAutowireCapableBeanFactory.java:515)[spring-beans-5.1.5.RELEASE.jar:5.1.5.RELEASE]       在org.springframework.beans.factory.support.AbstractBeanFactory.lambda $ doGetBean $ 0(AbstractBeanFactory.java:320)[spring-beans-5.1.5.RELEASE.jar:5.1.5.RELEASE]       在org.springframework.beans.factory.support.DefaultSingletonBeanRegistry.getSingleton(DefaultSingletonBeanRegistry.java:222)〜[spring-beans-5.1.5.RELEASE.jar:5.1.5.RELEASE]       在org.springframework.beans.factory.support.AbstractBeanFactory.doGetBean(AbstractBeanFactory.java:318)[spring-beans-5.1.5.RELEASE.jar:5.1.5.RELEASE]       在org.springframework.beans.factory.support.AbstractBeanFactory.getBean(AbstractBeanFactory.java:199)[spring-beans-5.1.5.RELEASE.jar:5.1.5.RELEASE]       在org.springframework.context.support.AbstractApplicationContext.getBean(AbstractApplicationContext.java:1105)〜[spring-context-5.1.5.RELEASE.jar:5.1.5.RELEASE]       在org.springframework.context.support.AbstractApplicationContext.finishBeanFactoryInitialization(AbstractApplicationContext.java:867)〜[spring-context-5.1.5.RELEASE.jar:5.1.5.RELEASE]       在org.springframework.context.support.AbstractApplicationContext.refresh(AbstractApplicationContext.java:549)〜[spring-context-5.1.5.RELEASE.jar:5.1.5.RELEASE]       在org.springframework.boot.web.servlet.context.ServletWebServerApplicationContext.refresh(ServletWebServerApplicationContext.java:142)〜[spring-boot-2.1.3.RELEASE.jar:2.1.3.RELEASE]       在org.springframework.boot.SpringApplication.refresh(SpringApplication.java:775)〜[spring-boot-2.1.3.RELEASE.jar:2.1.3.RELEASE]       在org.springframework.boot.SpringApplication.refreshContext(SpringApplication.java:397)〜[spring-boot-2.1.3.RELEASE.jar:2.1.3.RELEASE]       在org.springframework.boot.SpringApplication.run(SpringApplication.java:316)〜[spring-boot-2.1.3.RELEASE.jar:2.1.3.RELEASE]       在org.springframework.boot.SpringApplication.run(SpringApplication.java:1260)〜[spring-boot-2.1.3.RELEASE.jar:2.1.3.RELEASE]       在org.springframework.boot.SpringApplication.run(SpringApplication.java:1248)〜[spring-boot-2.1.3.RELEASE.jar:2.1.3.RELEASE]       在com.example.migration.MigrationApplication.main(MigrationApplication.java:10)〜[classes /:na]       在sun.reflect.NativeMethodAccessorImpl.invoke0(本机方法)〜[na:1.8.0_181]       在sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:62)〜[na:1.8.0_181]       在sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)〜[na:1.8.0_181]       在java.lang.reflect.Method.invoke(Method.java:498)〜[na:1.8.0_181]       在org.springframework.boot.devtools.restart.RestartLauncher.run(RestartLauncher.java:49)〜[spring-boot-devtools-2.1.3.RELEASE.jar:2.1.3.RELEASE]   由以下原因引起:java.sql.SQLSyntaxErrorException:SQL语法有错误。检查与您的MySQL服务器版本相对应的手册,以在第1行的'poxos not null,primary key(id))engine = InnoDB'附近使用正确的语法       在com.mysql.cj.jdbc.exceptions.SQLError.createSQLException(SQLError.java:120)〜[mysql-connector-java-8.0.15.jar:8.0.15]       在com.mysql.cj.jdbc.exceptions.SQLError.createSQLException(SQLError.java:97)〜[mysql-connector-java-8.0.15.jar:8.0.15]       在com.mysql.cj.jdbc.exceptions.SQLExceptionsMapping.translateException(SQLExceptionsMapping.java:122)〜[mysql-connector-java-8.0.15.jar:8.0.15]       在com.mysql.cj.jdbc.StatementImpl.executeInternal(StatementImpl.java:782)〜[mysql-connector-java-8.0.15.jar:8.0.15]       在com.mysql.cj.jdbc.StatementImpl.execute(StatementImpl.java:666)〜[mysql-connector-java-8.0.15.jar:8.0.15]       在com.zaxxer.hikari.pool.ProxyStatement.execute(ProxyStatement.java:95)〜[HikariCP-3.2.0.jar:na]       在com.zaxxer.hikari.pool.HikariProxyStatement.execute(HikariProxyStatement.java)〜[HikariCP-3.2.0.jar:na]       在org.hibernate.tool.schema.internal.exec.GenerationTargetToDatabase.accept(GenerationTargetToDatabase.java:54)〜[hibernate-core-5.3.7.Final.jar:5.3.7.Final]       ...省略了39个通用框架   ,

0 个答案:

没有答案