I tried adding a new attribute to an entity Customer which already has data stored in the database:
private boolean isArchived;
This gives me the following error when i start spring and try to update the tables:
Error executing DDL "alter table customer add column is_archived boolean not null" via JDBC Statement
Is that because he tries to initialize isArchived with null for the already existing rows and the primitive type cant be null? Is there a way to just initialize them with false instead or do i have to use Boolean instead of boolean to allow null values(which i would like not to allow)?
It's because existing rows can't have null values, with the new non-null column. The way to do is to provide a default value. You can do it like below:
@Column(nullable=false, columnDefinition = "BOOLEAN DEFAULT FALSE")
private boolean isArchived;
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With