Reputation: 211
I was trying to add an field to my entity as a CLOB. When using the JHipster CLI it was no problem to add it.
Now, when i trying to start my application i get the following validation error from liquibase:
liquibase.exception.ValidationFailedException: Validation Failed:
1 change sets check sum
config/liquibase/changelog/20170221193921_xxxxxxxx.xml::20170221193921-1::jhipster was: 7:d8b3f42d8d4d523c7b14f93b4c7657c7 but is now: 7:a2a365179a0d231c2771ebd79f51b1fc
i also tried the following:
./mvnw liquibase:clearCheckSums
The result was BUILD SUCCESS
.
i also tried ./mvnw liquibase:update and updateSQL, same result.
Can anyone tell me what my problem is with JHipster?
Upvotes: 11
Views: 16707
Reputation: 16284
All the above answers are valid but since JHipster 7.0.0 you can use jhipster --incremental-changelog
to generate your app to avoid modifying initial creation changelog by creating changelog only for what has changed.
It supports:
but it's not perfect because it does not support any attribute change like type and constraints
Also you can't enable it after project generation, it should be used from beginning.
Hopefully, this should be the default behavior some day.
Upvotes: 0
Reputation: 5877
When we use liquibase all entity changes that happen later should be captured as separate changelogs(For eg. altering a table like adding a new column). Jhipster cli always seems to overwrite the entities(whichever changed) corresponding liquibase files(usually of the pattern 'config/liquibase/changelog/20180607110114_added_entity_Employee.xml'
). Therefore the entities liquibase file's checksum changes as it has new content now. And in your database, there is a table called DATABASECHANGELOG
which stores which all changeLogs were applied and this has checksum data.
Now when you start your application you will get error because your latest liquibase changeLog of modified entity's checksum is different from the last time(database will have a checksum for this liquibase file for previous verison) you ran.
mvn liquibase:clearCheckSums
is not the right approach most of the time unless needed. This actually clears all checksums in the database. You lose track of the changes that had happened which is usually not intended. These features of liquibase makes sense for eg like when you want to rollback the new changes you have applied. If you clear checksums and run the application it will compute new checksums you lose the track and can get you into trouble if not enough attention is paid.
Proper solution:
entity sub-generator
or jdl import
or manual changes to your entities directly
.'.._added_entity_...'
. For eg. 'config/liquibase/changelog/20180607110114_added_entity_Employee.xml'
.mvn liquibase:diff
. This will generate a changeLog file. Check it manually once and add it to liquibase's master.xml
file. Adding to master file is must as liquibase refers to this file for all changeLogs.To summarize, jhipster cli overwrites the entities liquibase files. Revert them and run mvn liquibase:diff
to capture the new changes to the entites in a new changeLog instead of overwriting the previously generated liquibase file. We can see that checksum error is resolved and also database changes are captured in liquibase as well.
References:
Database updates
Upvotes: 24
Reputation: 56
The quick solution is to run:
./mvnw clean
./mvnw liquibase:clearCheckSums
This will work, however you're missing the point of using Liquibase to track changes. For development purposes it's OK.
The correct way to fix that is to run ./mvnw liquibaseDiffChangeLog
to create a diff changelog of the changes made to your database. This can then be added to the master.xml file as a new entry which can be applied next time you fire your app.
Upvotes: 1
Reputation: 105
When we add a column in Jhipster using the command jhpster entity xxxx
it is not added as a seperate changeset, instead the column is added in the existing change set for create table and as there is a change in the file new checksum is generated and on startup it is different from the DB so validation fails
<changeSet id="20181209164925-1" author="jhipster" >
<createTable tableName="xxxxxx">
<column name="id" type="bigint" autoIncrement="${autoIncrement}">
<constraints primaryKey="true" nullable="false"/>
</column>
<column name="xxxxx" type="integer">
<constraints nullable="true" />
</column>
<column name="xxxxx" type="integer">
<constraints nullable="true" />
</column>
<column name="xxxxxx" type="varchar(140)">
<constraints nullable="true" />
</column>
<column name="xxxx" type="bigint">
<constraints nullable="true" />
</column>
<!-- jhipster-needle-liquibase-add-column - JHipster will add columns here, do not remove-->
</createTable>
To fix this issue add a new changeset with add column as tag ..shown below
<changeSet id="20181209164925-2" author="jhipster" runOnChange="true">
<addColumn tableName="xxxxxx">
<column name="xxxxxx" type="date"></column>
</addColumn>
Refer https://www.liquibase.org/documentation/changes/add_column.html
Upvotes: 1
Reputation: 49
Try Executing the following query in your DB: UPDATE DATABASECHANGELOG SET MD5SUM = null WHERE ID='YOUR TABLE ID';
YOUR TABLE ID in this case seems to be = 20170221193921-1.
Upvotes: 4