Hi Nitin,

Thank you for your comment.
I did not add any additional class in models.py.
I just added two fields under the same class, List.

class List(models.Model):
item = models.CharField(max_length=200)
completed = models.BooleanField(default=False)
*created_at = models.DateTimeField('date', auto_now_add=True, null = 
True)  *
* updated_at = models.DateTimeField('update', auto_now=True, null = True)  *

In admin.py, I did not change anything.

#this is my admin.py
from django.contrib import admin
from .models import List
# Register your models here. then go to admin page and re-load
admin.site.register(List)

Why new columns (or in other words, new fields) do not show up in my admin 
site? Even though I did makemigrations/migrate.


Thank you for your help!

Nori



On Tuesday, February 5, 2019 at 9:58:30 PM UTC-5, Nitin Kalmaste wrote:
>
> You need to add python's magic method in order to return something from 
> the models you have created. Also you have to register your models to 
> admin.py file. You can refer Django documents for that.
>
> On Wed, Feb 6, 2019, 8:03 AM Atsunori Kaneshige <[email protected] 
> <javascript:> wrote:
>
>> Hi, Django masters!
>>
>> My app has simple models.py
>> just two fields like below.
>>
>> #models.py
>> class List(models.Model):
>> item = models.CharField(max_length=200)
>> completed = models.BooleanField(default=False)
>>
>> #migration 0001
>> class Migration(migrations.Migration):
>>
>>     initial = True
>>
>>     dependencies = [
>>     ]
>>
>>     operations = [
>>         migrations.CreateModel(
>>             name='List',
>>             fields=[
>>                 ('id', models.AutoField(auto_created=True, 
>> primary_key=True, serialize=False, verbose_name='ID')),
>>                 ('item', models.CharField(max_length=200)),
>>                 ('completed', models.BooleanField(default=False)),
>>             ],
>>         ),
>>     ]
>>
>> and after makemigrations/migrate, the app was working no problem.
>> *Then, I wanted to try adding two more fields.*
>>
>> #new models.py
>> class List(models.Model):
>> item = models.CharField(max_length=200)
>> completed = models.BooleanField(default=False)
>> *created_at = models.DateTimeField('date', auto_now_add=True, null = 
>> True)  *
>> * updated_at = models.DateTimeField('update', auto_now=True, null = 
>> True)  *
>>
>> #migrations 0002
>> class Migration(migrations.Migration):
>>
>>     dependencies = [
>>         ('pages', '0001_initial'),
>>     ]
>>
>>     operations = [
>>         migrations.AddField(
>>             model_name='list',
>>             name='created_at',
>>             field=models.DateTimeField(auto_now_add=True, null=True, 
>> verbose_name='date'),
>>         ),
>>         migrations.AddField(
>>             model_name='list',
>>             name='updated_at',
>>             field=models.DateTimeField(auto_now=True, null=True, 
>> verbose_name='update'),
>>         ),
>>     ]
>>
>>
>> Django doc says that I need to add '*null = True*' because I am using 
>> postgresql as my database.
>> Without '*null = True*', the program throws an error saying that column 
>> pages_list.created_at doesn't exist etc. when I try to see the web page. 
>> But, with '*null = True*', I successfully did makemigration and migrate, 
>> then web page showed up without any problem.
>>
>> *But, when I go to admin, I could not find any fields that I though I 
>> created.*
>> I also looked at the table in my postgresql, but again, there are only 
>> original columns, but not other two columns.
>>
>> Do you know how to add new columns by changing models.py??
>> What should I take care to successfully modify models and add new columns 
>> in my database table (postgresql in my case).
>>
>> I really appreciate your advice!
>>
>> Looking forward to hearing from you.
>>
>> Nori
>>
>>  
>>
>>
>>
>> -- 
>> You received this message because you are subscribed to the Google Groups 
>> "Django users" group.
>> To unsubscribe from this group and stop receiving emails from it, send an 
>> email to [email protected] <javascript:>.
>> To post to this group, send email to [email protected] 
>> <javascript:>.
>> Visit this group at https://groups.google.com/group/django-users.
>> To view this discussion on the web visit 
>> https://groups.google.com/d/msgid/django-users/a1d71d4c-1500-4972-af57-dc23f5d1ff20%40googlegroups.com
>>  
>> <https://groups.google.com/d/msgid/django-users/a1d71d4c-1500-4972-af57-dc23f5d1ff20%40googlegroups.com?utm_medium=email&utm_source=footer>
>> .
>> For more options, visit https://groups.google.com/d/optout.
>>
>
> On Wed, Feb 6, 2019, 8:03 AM Atsunori Kaneshige <[email protected] 
> <javascript:> wrote:
>
>> Hi, Django masters!
>>
>> My app has simple models.py
>> just two fields like below.
>>
>> #models.py
>> class List(models.Model):
>> item = models.CharField(max_length=200)
>> completed = models.BooleanField(default=False)
>>
>> #migration 0001
>> class Migration(migrations.Migration):
>>
>>     initial = True
>>
>>     dependencies = [
>>     ]
>>
>>     operations = [
>>         migrations.CreateModel(
>>             name='List',
>>             fields=[
>>                 ('id', models.AutoField(auto_created=True, 
>> primary_key=True, serialize=False, verbose_name='ID')),
>>                 ('item', models.CharField(max_length=200)),
>>                 ('completed', models.BooleanField(default=False)),
>>             ],
>>         ),
>>     ]
>>
>> and after makemigrations/migrate, the app was working no problem.
>> *Then, I wanted to try adding two more fields.*
>>
>> #new models.py
>> class List(models.Model):
>> item = models.CharField(max_length=200)
>> completed = models.BooleanField(default=False)
>> *created_at = models.DateTimeField('date', auto_now_add=True, null = 
>> True)  *
>> * updated_at = models.DateTimeField('update', auto_now=True, null = 
>> True)  *
>>
>> #migrations 0002
>> class Migration(migrations.Migration):
>>
>>     dependencies = [
>>         ('pages', '0001_initial'),
>>     ]
>>
>>     operations = [
>>         migrations.AddField(
>>             model_name='list',
>>             name='created_at',
>>             field=models.DateTimeField(auto_now_add=True, null=True, 
>> verbose_name='date'),
>>         ),
>>         migrations.AddField(
>>             model_name='list',
>>             name='updated_at',
>>             field=models.DateTimeField(auto_now=True, null=True, 
>> verbose_name='update'),
>>         ),
>>     ]
>>
>>
>> Django doc says that I need to add '*null = True*' because I am using 
>> postgresql as my database.
>> Without '*null = True*', the program throws an error saying that column 
>> pages_list.created_at doesn't exist etc. when I try to see the web page. 
>> But, with '*null = True*', I successfully did makemigration and migrate, 
>> then web page showed up without any problem.
>>
>> *But, when I go to admin, I could not find any fields that I though I 
>> created.*
>> I also looked at the table in my postgresql, but again, there are only 
>> original columns, but not other two columns.
>>
>> Do you know how to add new columns by changing models.py??
>> What should I take care to successfully modify models and add new columns 
>> in my database table (postgresql in my case).
>>
>> I really appreciate your advice!
>>
>> Looking forward to hearing from you.
>>
>> Nori
>>
>>  
>>
>>
>>
>> -- 
>> You received this message because you are subscribed to the Google Groups 
>> "Django users" group.
>> To unsubscribe from this group and stop receiving emails from it, send an 
>> email to [email protected] <javascript:>.
>> To post to this group, send email to [email protected] 
>> <javascript:>.
>> Visit this group at https://groups.google.com/group/django-users.
>> To view this discussion on the web visit 
>> https://groups.google.com/d/msgid/django-users/a1d71d4c-1500-4972-af57-dc23f5d1ff20%40googlegroups.com
>>  
>> <https://groups.google.com/d/msgid/django-users/a1d71d4c-1500-4972-af57-dc23f5d1ff20%40googlegroups.com?utm_medium=email&utm_source=footer>
>> .
>> For more options, visit https://groups.google.com/d/optout.
>>
>

-- 
You received this message because you are subscribed to the Google Groups 
"Django users" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to [email protected].
To post to this group, send email to [email protected].
Visit this group at https://groups.google.com/group/django-users.
To view this discussion on the web visit 
https://groups.google.com/d/msgid/django-users/12d0114d-b6d1-4e5d-ad5f-c25cad8a670a%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.

Reply via email to