I want to convert the following excerpt of a create table SQL script into Liquibase:
SuccessInd char(1) NOT NULL
CONSTRAINT DefALog_SuccessInd DEFAULT ‘N’
I want something along the lines of
<constraints uniqueConstraintName="DefALog_SuccessInd" defaultValue="N />
</column>
<p>However, defaultValue must go into the column tag (and can you even have multiple constraints per column?). Is there any way to assign a constraint name to a default value?</p>
I think you can just have one constraint block per column, but you can combine the two you have:
<constraints nullable="false" uniqueConstraintName="DefALog_SuccessInd" defaultValue="N />
</column>
<p>should do what you want.</p>
<p>Nathan</p>
Hmm, still get the error that defaultValue is not allowed inside a constraint tag. I guess I have to use a for named default constrains
What do you have for your xsd reference on the top of your xml file? uniqueConstraintName should be allowed in
Nathan
Still using 1.9
<databaseChangeLog xmlns=“http://www.liquibase.org/xml/ns/dbchangelog/1.9” xmlns:xsi=“http://www.w3.org/2001/XMLSchema-instance” xsi:schemaLocation=“http://www.liquibase.org/xml/ns/dbchangelog/1.9 http://www.liquibase.org/xml/ns/dbchangelog/dbchangelog-1.9.xsd”>
uniqueConstraintName is allowed, but defaultValue has to go in the column tag.
Is allowed, however this way wouldn’t the constraint name be tied to nullability instead of the default value?
Sorry, I get your question now. There isn’t a way to set the default constraint name at this point. The uniqueConstraintName is for if you set a unique constraint. If you want it named, you’ll have to use the tag. Any idea how many database types allow setting of default constraint names?
Nathan
Nope, no idea. Guess I was forgetting how many database types are served by liquibase. Thank you.
In case a fellow newbie has the same problem, I used the following
...
ALTER TABLE ] ADD CONSTRAINT [constraint name] DEFAULT [value] for [column];
Hi Nathan,
Is it now possible to set the default constraint name? I am using liquibase 3.6.3, generated db changelog which gives out the following
Attribute ‘defaultValueConstraintName’ is not allowed to appear in element ‘column’.