# I have an issue with column name on Django migrations after making manual migration

**URL:** <https://forum.djangoproject.com/t/i-have-an-issue-with-column-name-on-django-migrations-after-making-manual-migration/40546>\
**Category:** Using the ORM\
**Created:** [April 21, 2025, 7:18am UTC](https://forum.djangoproject.com/t/i-have-an-issue-with-column-name-on-django-migrations-after-making-manual-migration/40546 "2025-04-21T07:18:58Z")\
**Posts on this page:** 12\
**Page:** 2

<div class="post-metadata">

**Author:** ![XCanG](https://sea2.discourse-cdn.com/flex026/user_avatar/forum.djangoproject.com/xcang/32/28190_2.png) [@XCanG](https://forum.djangoproject.com/u/XCanG)\
**Post date:** [April 21, 2025, 5:37pm UTC](https://forum.djangoproject.com/t/i-have-an-issue-with-column-name-on-django-migrations-after-making-manual-migration/40546/21 "2025-04-21T17:37:06Z")

</div>

So, how to bypass that? I would’ve use Django native methods, but it doesn’t support `USING` keyword, and I can’t make reverse SQL with that method either, so how to solve this?

---

<div class="post-metadata">

**Author:** ![ChathuraGH](https://sea2.discourse-cdn.com/flex026/user_avatar/forum.djangoproject.com/chathuragh/32/27563_2.png) [@ChathuraGH](https://forum.djangoproject.com/u/ChathuraGH)\
**Post date:** [April 21, 2025, 5:39pm UTC](https://forum.djangoproject.com/t/i-have-an-issue-with-column-name-on-django-migrations-after-making-manual-migration/40546/22 "2025-04-21T17:39:32Z")

</div>

I got this idea, you may have to test it before using in production.

**1) method**

Frist run makemigrations.

Then open generated migration file in IDE.

Then `IgnoreMigration`,

```auto
    from django.db import migrations
    import django_migration_linter as linter
    
    class Migration(migrations.Migration):
        operations = [
            linter.IgnoreMigration(),
        ]

```

**2) method**

Empty Migration: Create an empty migration, apply it, then replace it with the actual migration.

```auto

    python manage.py makemigrations --empty myapp
    python manage.py migrate myapp

```

---

<div class="post-metadata">

**Author:** ![philgyford](https://sea2.discourse-cdn.com/flex026/user_avatar/forum.djangoproject.com/philgyford/32/14295_2.png) [@philgyford](https://forum.djangoproject.com/u/philgyford)\
**Post date:** [April 21, 2025, 5:43pm UTC](https://forum.djangoproject.com/t/i-have-an-issue-with-column-name-on-django-migrations-after-making-manual-migration/40546/23 "2025-04-21T17:43:09Z")

</div>

Are you able to revert your code back to how it was before you started these changes? I’m not clear what’s already deployed to production or not.

Because there’s probably a better way to do this if you’re able to start over. i.e., don’t manually make changes to the database, only do it using migrations.

---

<div class="post-metadata">

**Author:** ![XCanG](https://sea2.discourse-cdn.com/flex026/user_avatar/forum.djangoproject.com/xcang/32/28190_2.png) [@XCanG](https://forum.djangoproject.com/u/XCanG)\
**Post date:** [April 21, 2025, 5:44pm UTC](https://forum.djangoproject.com/t/i-have-an-issue-with-column-name-on-django-migrations-after-making-manual-migration/40546/24 "2025-04-21T17:44:21Z")

</div>

I can, my migration is revertable and not deployed yet.

But django migrations are very restricted and not support some specific keywords or funcationality that available only on single DB (in my case Postgres), for example.

---

<div class="post-metadata">

**Author:** ![philgyford](https://sea2.discourse-cdn.com/flex026/user_avatar/forum.djangoproject.com/philgyford/32/14295_2.png) [@philgyford](https://forum.djangoproject.com/u/philgyford)\
**Post date:** [April 21, 2025, 5:51pm UTC](https://forum.djangoproject.com/t/i-have-an-issue-with-column-name-on-django-migrations-after-making-manual-migration/40546/25 "2025-04-21T17:51:26Z")

</div>

So I would start over. Do all the changes to the structure that you can by altering the Django model and running `makemigrations`. Avoid using RawSQL as much as possible.

Something like:

1. Add new column to the model. Make migration and migrate.
2. Create a [data migration](https://docs.djangoproject.com/en/5.2/topics/migrations/#data-migrations) to populate the new column with data (by updating/creating Django objects, not directly using sql). Migrate.
3. Remove the old column. Make migration and migrate.

---

<div class="post-metadata">

**Author:** ![XCanG](https://sea2.discourse-cdn.com/flex026/user_avatar/forum.djangoproject.com/xcang/32/28190_2.png) [@XCanG](https://forum.djangoproject.com/u/XCanG)\
**Post date:** [April 21, 2025, 5:58pm UTC](https://forum.djangoproject.com/t/i-have-an-issue-with-column-name-on-django-migrations-after-making-manual-migration/40546/26 "2025-04-21T17:58:12Z")

</div>

I don’t really like approach or adding and removing columns, because that will put column to an end when it can be modified in place. But I’m also not particularly know the intricates of this methods. I usually work with different library, it just that I’ve been put on this project that was already make in Django and need some refactoring. This is the first Django project for me.

---

<div class="post-metadata">

**Author:** ![philgyford](https://sea2.discourse-cdn.com/flex026/user_avatar/forum.djangoproject.com/philgyford/32/14295_2.png) [@philgyford](https://forum.djangoproject.com/u/philgyford)\
**Post date:** [April 21, 2025, 6:00pm UTC](https://forum.djangoproject.com/t/i-have-an-issue-with-column-name-on-django-migrations-after-making-manual-migration/40546/27 "2025-04-21T18:00:00Z")

</div>

> [@XCanG](#):
>
> because that will put column to an end when it can be modified in place

Sorry, I don’t understand what you mean by this.

You want to change some data from a string, to a foreign key. The easiest way is to create a new fk column, populate it with data, then delete the old column.

---

<div class="post-metadata">

**Author:** ![XCanG](https://sea2.discourse-cdn.com/flex026/user_avatar/forum.djangoproject.com/xcang/32/28190_2.png) [@XCanG](https://forum.djangoproject.com/u/XCanG)\
**Post date:** [April 21, 2025, 6:03pm UTC](https://forum.djangoproject.com/t/i-have-an-issue-with-column-name-on-django-migrations-after-making-manual-migration/40546/28 "2025-04-21T18:03:21Z")

</div>

When new column is added to a table it always added to it’s end,  
e.g. if table look before: `id, name, status, description, date, user`, doing your way will restructure it to `id, name, description, date, user, status_id`

---

<div class="post-metadata">

**Author:** ![XCanG](https://sea2.discourse-cdn.com/flex026/user_avatar/forum.djangoproject.com/xcang/32/28190_2.png) [@XCanG](https://forum.djangoproject.com/u/XCanG)\
**Post date:** [April 21, 2025, 6:05pm UTC](https://forum.djangoproject.com/t/i-have-an-issue-with-column-name-on-django-migrations-after-making-manual-migration/40546/29 "2025-04-21T18:05:58Z")

</div>

Also I’m not sure how to make that action within migration using django methods.

---

<div class="post-metadata">

**Author:** ![philgyford](https://sea2.discourse-cdn.com/flex026/user_avatar/forum.djangoproject.com/philgyford/32/14295_2.png) [@philgyford](https://forum.djangoproject.com/u/philgyford)\
**Post date:** [April 21, 2025, 6:06pm UTC](https://forum.djangoproject.com/t/i-have-an-issue-with-column-name-on-django-migrations-after-making-manual-migration/40546/30 "2025-04-21T18:06:14Z")

</div>

> [@XCanG](#):
>
> When new column is added to a table it always added to it’s end,

Why does that matter?

> [@XCanG](#):
>
> Also I’m not sure how to make that action within migration using django methods.

What action?

---

<div class="post-metadata">

**Author:** ![XCanG](https://sea2.discourse-cdn.com/flex026/user_avatar/forum.djangoproject.com/xcang/32/28190_2.png) [@XCanG](https://forum.djangoproject.com/u/XCanG)\
**Post date:** [April 21, 2025, 6:15pm UTC](https://forum.djangoproject.com/t/i-have-an-issue-with-column-name-on-django-migrations-after-making-manual-migration/40546/31 "2025-04-21T18:15:40Z")

</div>

> [@philgyford](#):
>
> What action?

Oups, I misspelled, I wanted to say “within one migration”, theoretically I can make two columns as existing `status` and new as `status_id` of foreign type, but I’m not sure if Django will name it properly as `status_id` or will add another id to it’s end `status_id_id`.

And speaking of columns, there is one issue, that I put into spoiler in first message regarding my exact case, but it may be a typing typo from linter (not sure), it doesn’t see `db_default` on Foreign Keys and even in migration file it erroring out about it.

 ![image](https://us1.discourse-cdn.com/flex026/uploads/djangoproject/original/3X/f/b/fb8f17f5d5af8e22e5e33ea72093c2fc99d653d1.png)

---

<div class="post-metadata">

**Author:** ![philgyford](https://sea2.discourse-cdn.com/flex026/user_avatar/forum.djangoproject.com/philgyford/32/14295_2.png) [@philgyford](https://forum.djangoproject.com/u/philgyford)\
**Post date:** [April 21, 2025, 6:30pm UTC](https://forum.djangoproject.com/t/i-have-an-issue-with-column-name-on-django-migrations-after-making-manual-migration/40546/32 "2025-04-21T18:30:19Z")

</div>

> [@XCanG](#):
>
> theoretically I can make two columns as existing `status` and new as `status_id` of foreign type, but I’m not sure if Django will name it properly as `status_id` or will add another id to it’s end `status_id_id`.

So do this:

1. Add new column, `new_status`, to the model. Make migration and migrate.
2. Create a [data migration](https://docs.djangoproject.com/en/5.2/topics/migrations/#data-migrations) to populate the new column with data (by updating/creating Django objects, not directly using sql). Migrate.
3. Remove the old column. Make migration and migrate.
4. Rename `new_status` to `status`. Make migration and migrate.

I don’t know about that error. I would try this first, with the only bit of migration you write yourself being the code in step 2.

[Previous page](https://forum.djangoproject.com/t/i-have-an-issue-with-column-name-on-django-migrations-after-making-manual-migration/40546.md?page=1)
