0

I created a dummy project just to test the new field JSONField of Django but the column doesn't not appear to be created (I am using Postgresql).

class Author(models.Model):

   name = models.CharField(max_length=50)
   description = models.TextField()
   slug = models.SlugField()
   details = models.JSONField()

   class Meta:
     verbose_name = "Author"

   def __str__(self):
      return self.name

If i go to the database, the column is not created -- screenshot

When i go to the admin view page of the table Author i get the following error -- screenshot

The error in the admin panel is understandable: you cannot view a column that does not exist. Do you guys have the same error? I can't find this error with JSONField anywhere.

Thanks

Note: This is my first post.

EDIT I create all the fields in the same time. Migration file:

# Generated by Django 3.1.3 on 2020-11-20 10:35

from django.db import migrations, models


class Migration(migrations.Migration):

    initial = True

    dependencies = [
    ]

    operations = [
        migrations.CreateModel(
            name='Author',
            fields=[
                ('id', models.AutoField(auto_created=True, primary_key=True, serialize=False, verbose_name='ID')),
                ('name', models.CharField(max_length=50)),
                ('description', models.TextField()),
                ('slug', models.SlugField()),
                ('details', models.JSONField()),
            ],
            options={
                'verbose_name': 'Author',
            },
        ),
    ]

Migrated with sucess:

Migrations for 'blog':
  blog/migrations/0001_initial.py
    - Create model Author
Andre
  • 1
  • 1
  • Have you migrated your changes via `python manage.py makemigrations` and `python manage.py migrate` – Lewis Nov 20 '20 at 10:55
  • Question edited – Andre Nov 20 '20 at 11:09
  • 1
    if you already migrated. Then I guess migration probably frick up somewhere, try removing the field, migrate, and then add the field back. or maybe you have multiple databases(?) – Alvi15 Nov 20 '20 at 11:18
  • If i remove the field, a migration is created with the instruction to remove it. But that doesn't work because the migration fails: "column "details" of relation "blog_author" does not exist" – Andre Nov 20 '20 at 11:21

1 Answers1

0

check that you migration was applied to the right database

babak gholamirad
  • 407
  • 4
  • 10
  • Hi, i forgot to mention that i create all the fields at the same time. I edit the question – Andre Nov 20 '20 at 11:09
  • I added a new field and the same table that i showed is updated. Seems that the field JSONField is the problem here – Andre Nov 20 '20 at 11:22
  • If you run manage dbshell, you could look to see the table description either with .schema (sqlite) or \d tablename with posgres – boatcoder Sep 07 '21 at 23:57