# DB migration version 20210714173022 fails when having skipped post deployment migrations before

**URL:** https://meta.discourse.org/t/db-migration-version-20210714173022-fails-when-having-skipped-post-deployment-migrations-before/204660
**Category:** Bug
**Created:** [September 28, 2021, 3:49pm UTC](https://meta.discourse.org/t/db-migration-version-20210714173022-fails-when-having-skipped-post-deployment-migrations-before/204660 "2021-09-28T15:49:51Z")
**Posts on this page:** 4
**Page:** 1

<div class="post-metadata">

### Author: ![thabbs](https://sea3.discourse-cdn.com/meta/user_avatar/meta.discourse.org/thabbs/32/82150_2.png) [@thabbs](https://meta.discourse.org/u/thabbs)
#### Post date: [September 28, 2021, 3:49pm UTC](https://meta.discourse.org/t/db-migration-version-20210714173022-fails-when-having-skipped-post-deployment-migrations-before/204660/1 "2021-09-28T15:49:52Z")

</div>

Was updating to stable (v2.7.8) in the first container having SKIP\_POST\_DEPLOYMENT\_MIGRATIONS enabled.  
When running the second time in the other container with the skip-option disabled the migration task CorrectlyMoveAssignmentsFromCustomFieldsToATable failed:

```plaintext
PG::NotNullViolation: ERROR: null value in column "assigned_to_type"
of relation "assignments" violates not-null constraint

```

As far I can see the upgrade task AddAssignedToTypeToAssignments (creating the not-null constraint) should not be performed until CorrectlyMoveAssignmentsFromCustomFieldsToATable has been finished.

As workaround I was doing:

```plaintext
INSERT INTO assignments
(assigned_to_id, assigned_by_user_id, topic_id, created_at, updated_at,assigned_to_type)
SELECT
  assigned_to.value::integer,
  assigned_by.value::integer,
  assigned_by.topic_id,
  assigned_by.created_at,
  assigned_by.updated_at,
  'User'
FROM topic_custom_fields assigned_by
INNER JOIN topic_custom_fields assigned_to
ON assigned_to.topic_id = assigned_by.topic_id
WHERE assigned_by.name = 'assigned_by_id'
AND assigned_to.name = 'assigned_to_id'
ORDER BY assigned_by.created_at DESC
ON CONFLICT DO NOTHING;

INSERT INTO schema_migration_details
(version,
name,
hostname,
git_version,
rails_version,
duration,
direction,
created_at)
values(
'20210714173022',
'CorrectlyMoveAssignmentsFromCustomFieldsToATable',
'ce4fb45daf62',
'98b0621d538fa4e8a53e1e74127c24c384be9b58',
'6.1.3.2',
0,
'up',
'2021-09-28 15:20:00.123456'
);

INSERT INTO schema_migrations values('20210714173022');

```

Afterwords I was able to rebuild the container.

---

<div class="post-metadata">

### Author: ![kris.kotlarek](https://sea3.discourse-cdn.com/meta/user_avatar/meta.discourse.org/kris.kotlarek/32/176919_2.png) [@kris.kotlarek](https://meta.discourse.org/u/kris.kotlarek)
#### Post date: [September 29, 2021, 8:35am UTC](https://meta.discourse.org/t/db-migration-version-20210714173022-fails-when-having-skipped-post-deployment-migrations-before/204660/4 "2021-09-29T08:35:07Z")

</div>

Thank you for your investigation, we fixed that migration with PR:

[https://github.com/discourse/discourse-assign/pull/217](https://github.com/discourse/discourse-assign/pull/217)

---

<div class="post-metadata">

### Author: ![thabbs](https://sea3.discourse-cdn.com/meta/user_avatar/meta.discourse.org/thabbs/32/82150_2.png) [@thabbs](https://meta.discourse.org/u/thabbs)
#### Post date: [September 29, 2021, 8:36am UTC](https://meta.discourse.org/t/db-migration-version-20210714173022-fails-when-having-skipped-post-deployment-migrations-before/204660/5 "2021-09-29T08:36:38Z")

</div>

That was fast. Thank you 🙂

---

<div class="post-metadata">

### Author: ![sam](https://sea3.discourse-cdn.com/meta/user_avatar/meta.discourse.org/sam/32/102149_2.png) [@sam](https://meta.discourse.org/u/sam)
#### Post date: [May 22, 2025, 1:13am UTC](https://meta.discourse.org/t/db-migration-version-20210714173022-fails-when-having-skipped-post-deployment-migrations-before/204660/7 "2025-05-22T01:13:07Z")

</div>


