# Generated diffChangeLog creates constraint before creating column used in the constraint

**URL:** <https://forum.liquibase.org/t/generated-diffchangelog-creates-constraint-before-creating-column-used-in-the-constraint/5301>\
**Category:** Liquibase Development\
**Created:** [April 8, 2021, 6:04am UTC](https://forum.liquibase.org/t/generated-diffchangelog-creates-constraint-before-creating-column-used-in-the-constraint/5301 "2021-04-08T06:04:06Z")\
**Posts on this page:** 2\
**Page:** 1

<div class="post-metadata">

**Author:** ![josephwoolf](https://avatars.discourse-cdn.com/v4/letter/j/c6cbf5/32.png) [@josephwoolf](https://forum.liquibase.org/u/josephwoolf)\
**Post date:** [April 8, 2021, 6:04am UTC](https://forum.liquibase.org/t/generated-diffchangelog-creates-constraint-before-creating-column-used-in-the-constraint/5301/1 "2021-04-08T06:04:06Z")

</div>

I’ve currently using Liquibase to first do a diffChangeLog, validate, and then update the live developmental database. I noticed that the update failed when trying to update a constraint on a column. The problem is that the constraint is trying to be added despite the column not existing in the first place. In fact, the column is created after the constraint is.

Is this a bug in Liquibase? If not, how can I fix this issue?

I’ve pasted the file contains as follows:

```
-- liquibase formatted sql

-- changeset liquibase:1617859768566-3
ALTER TABLE Task ADD CONSTRAINT FK __Task__ projectID__3C69FB99 FOREIGN KEY (projectID) REFERENCES Projects (ID) ON UPDATE NO ACTION ON DELETE CASCADE;

-- changeset liquibase:1617859768566-4
ALTER TABLE Task ADD projectID bigint NOT NULL;

-- changeset liquibase:1617859768566-1
ALTER TABLE Task DROP CONSTRAINT FK __Task__ orgID__3D5E1FD2;

-- changeset liquibase:1617859768566-2
ALTER TABLE Task ADD CONSTRAINT FK __Task__ orgID__3D5E1FD2 FOREIGN KEY (orgID) REFERENCES Organizations (ID) ON UPDATE NO ACTION ON DELETE NO ACTION;
```

---

<div class="post-metadata">

**Author:** ![ronak](https://sea2.discourse-cdn.com/flex020/user_avatar/forum.liquibase.org/ronak/32/221_2.png) [@ronak](https://forum.liquibase.org/u/ronak)\
**Post date:** [April 19, 2021, 2:08pm UTC](https://forum.liquibase.org/t/generated-diffchangelog-creates-constraint-before-creating-column-used-in-the-constraint/5301/2 "2021-04-19T14:08:24Z")

</div>

Hi @josephwoolf ,

What DBMS are you using? Ex. postgres? I believe this is an issue and is being tracked here:

> <https://github.com/liquibase/liquibase/issues/1803>
>
> \## Environment
> \*\*Liquibase Version\*\*: 4.3.3
> 
> \*\*Database Vendor & Version\*\*: Post…gresql for sure, probably all
> 
> \## Description
> When running diffChangelog or generateChangelog, addColumn elements are added BEFORE corresponding createTable elements.
> 
> Example generated changelog:
> 
> \`\`\`
> \<changeSet author="Edi(generated)" id="1618486085348-1"\>
> \<addColumn tableName="baseInfo"\>
> \<column name="id" type="int4"\>
> \<constraints nullable="false"/\>
> \</column\>
> \</addColumn\>
> \</changeSet\>
> \<changeSet author="Edi (generated)" id="1618486085348-2"\>
> \<createTable tableName="baseInfo"\>
> \<column name="id" type="INTEGER"\>
> \<constraints nullable="false" primaryKey="true" primaryKeyName="baseInfo\_pkey"/\>
> \</column\>
> \<column name="first" type="VARCHAR(150)"/\>
> \<column name="middle" type="VARCHAR(150)"/\>
> \<column name="last" type="VARCHAR(150)"/\>
> \<column name="RandomId" type="INTEGER"/\>
> \</createTable\>
> \</changeSet\>
> \`\`\`
> 
> 
> 
> ┆Issue is synchronized with this \[Jira Bug\](https://datical.atlassian.net/browse/LB-1478) by \[Unito\](https://www.unito.io/learn-more)
> ┆Fix Versions: Liquibase 4.3.4

Thanks,

Ronak
