question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

Invalid default value for required ZonedDateTime - liquibase fails

See original GitHub issue
Overview 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"
}
  1. 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:closed
  • Created 6 years ago
  • Comments:6 (6 by maintainers)

github_iconTop GitHub Comments

1reaction
ruddellcommented, Oct 12, 2017

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

0reactions
pascalgrimaudcommented, Oct 26, 2017

I take this

Read more comments on GitHub >

github_iconTop Results From Across the Web

Liquibase: How to set the default value of a date column to be ...
now() is not completely fine for H2, I just got a correct result starting the h2 database with UTC like jdbc:h2:mem:./my_database;TIME ZONE=UTC (h2database...
Read more >
jhipster/generator-jhipster - Gitter
Reason: liquibase.exception.DatabaseException: Invalid default value for 'date_end' [Failed SQL: CREATE TABLE confapp_dev.event (id BIGINT AUTO_INCREMENT ...
Read more >
addDefaultValue | Liquibase Docs
The addDefaultValue changetype adds a default value to the database ... Type to your changeset with the needed attributes as it is shown...
Read more >
Jdbi 3 Developer Guide
The core Jdbi library. Required by all other components. jdbi3-sqlobject. SQL Object extension for declarative database access. Testing support.
Read more >
Data Types - H2 Database Engine
If length is not specified, 1 character is used by default. ... Possible values: TRUE, FALSE , and UNKNOWN ( NULL ). ......
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found