Invalid default value for required ZonedDateTime - liquibase fails
See original GitHub issueOverview of the issue
Liquibase changelogs are failing to pass for MySql because of required ZonedDateTime fields.
error: Reason: liquibase.exception.DatabaseException: Invalid default value for 'jhi_end'
Motivation for or Use Case
Changelog fails and tables aren’t created.
Reproduce the error
1.Create a JHipster application set up to use a MySql database (not h2). 1.Using the entity generator, create an entity having a ZonedDateTime field with the validation constraint required : entity :
{
"fluentMethods": true,
"relationships": [],
"fields": [
{
"fieldName": "end",
"fieldType": "ZonedDateTime",
"fieldValidateRules": [
"required"
]
}
],
"changelogDate": "20171006153741",
"dto": "no",
"service": "no",
"entityTableName": "lesson",
"jpaMetamodelFiltering": false,
"pagination": "no"
}
- Try to build the application
./mvnw
Related issues
This is the same as #5743 except it uses the entity generator rather than the JDL.
Suggest a Fix
I guess you can make something similar as #5743 but I didn’t understand that solution. I can only say that MySql timestamp column type require an explicit default value if you set it not nullable (such as CURRENT_TIMESTAMP
).
JHipster Version(s)
4.9.0
JHipster configuration
DBMS: mysql:5.7.19
docker-compose to set up the database:
version: '2'
services:
mysql:
image: mysql:5.7.19
container_name: scheduler-mysql
networks:
default:
ipv4_address: 10.10.10.1
environment:
MYSQL_ROOT_PASSWORD: password
volumes:
- ./persistence:/var/lib/mysql
pma:
image: phpmyadmin/phpmyadmin
container_name: scheduler-pma
links:
- mysql:db
networks:
default:
ipv4_address: 10.10.10.2
networks:
default:
driver: bridge
ipam:
driver: default
config:
- subnet: 10.10.10.0/24
gateway: 10.10.10.254
application-dev.yml:
datasource:
type: com.zaxxer.hikari.HikariDataSource
url: jdbc:mysql://10.10.10.1:3306/scheduler?useUnicode=true&characterEncoding=utf8&useSSL=false
username: root
password: password
hikari:
data-source-properties:
cachePrepStmts: true
prepStmtCacheSize: 250
prepStmtCacheSqlLimit: 2048
useServerPrepStmts: true
jpa:
database-platform: org.hibernate.dialect.MySQL5InnoDBDialect
database: MYSQL
show-sql: true
properties:
hibernate.id.new_generator_mappings: true
hibernate.cache.use_second_level_cache: true
hibernate.cache.use_query_cache: false
hibernate.generate_statistics: false
hibernate.cache.region.factory_class: io.github.jhipster.config.jcache.NoDefaultJCacheRegionFactory
- Checking this box is mandatory (this is just to show you read everything)
Issue Analytics
- State:
- Created 6 years ago
- Comments:6 (6 by maintainers)
We should document the flags so that users managing their own databases can be aware of them (my fault - I forgot after that PR). Maybe on Development#using-a-database, but it also applies to prod. I could also add a “Using MySQL” page like the other databases have
I take this