Models not appearing in db. Am I missing something?

73 views
Skip to first unread message

Shazwi Suwandi

unread,
Dec 15, 2014, 7:10:12 AM12/15/14
to django...@googlegroups.com
from django.db import models
from django.contrib.auth.models import User

# CORE APPLICATION
# Create your models here.
class Member(models.Model):
    user = models.OneToOneField(User)
    description = models.CharField(max_length=250)
    date_of_birth = models.DateField()
    location = models.CharField(max_length=100)
    gender = models.CharField(max_length=15)

class NewTable(models.Model):
test = models.CharField(max_length=25)

I've created some models and I used makemigrations and migrate. I went to my db and checked that only the default tables are there (auth_group ... django_session). I know that my connection settings are right and that I see new rows being added to the auth_user table when I create users in django admin page. 

Is there something that I must have missed out?

Shazwi Suwandi

unread,
Dec 15, 2014, 7:15:30 AM12/15/14
to django...@googlegroups.com
I've added 'core' to settings.py file under INSTALLED_APPS too.

David Palao

unread,
Dec 15, 2014, 11:03:23 AM12/15/14
to django...@googlegroups.com
Hello,
From your post I understand you did not write unittests for your models?
I would recommend to write some sensible tests for them and start
tracing your problem from the failures you should get.
Best,

David
> --
> 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 django-users...@googlegroups.com.
> To post to this group, send email to django...@googlegroups.com.
> Visit this group at http://groups.google.com/group/django-users.
> To view this discussion on the web visit
> https://groups.google.com/d/msgid/django-users/7af04f16-09a8-458d-8857-c71694394101%40googlegroups.com.
>
> For more options, visit https://groups.google.com/d/optout.

Shazwi Suwandi

unread,
Dec 15, 2014, 12:00:15 PM12/15/14
to django...@googlegroups.com
Hey David,

You're right, I have to practise writing tests along with my codes. However, just to clarify, data input and output works. I can call the data in the Member object. I'm just confused as to why the Member table does not show up in my postgres database. It's weird. 

Nevertheless, I'll start writing unit tests.

Mario Gudelj

unread,
Dec 16, 2014, 3:18:58 AM12/16/14
to django...@googlegroups.com

What's the output of your makemigrations command? If those models are inside core/models.py and your app is inside installed apps in settings this should totally work. The default name for the table will be appname_modelname. Do you get an error when accessing the model? How are you checking the db for tables?

Shazwi Suwandi

unread,
Dec 16, 2014, 5:33:36 AM12/16/14
to django...@googlegroups.com
Hey Mario,

The output I get when I use makemigrations is 

  0001_initial.py:

    - Create model Member.

I've double checked:

  • The 'Member' model is in core/models.py 
  • 'Core' is inside project/settings.py
I use python manage.py shell and I accessed the 'User' object and the linked 'Member' object to get the fields inside and it works. 
Furthermore, when I went to my db gui and try to delete the rows in the 'auth_user' table, it says that there is a constraint in 'core_member' table.

Here's the link to the image that shows all the tables I have. http://i.imgur.com/M1ZWznt.png

Shazwi Suwandi

unread,
Dec 16, 2014, 5:40:05 AM12/16/14
to django...@googlegroups.com
Hey guys,

I figured it was a problem with the app I'm using for the db. I went to use another app and now the tables are showing. Silly me. Thanks Mario and David for your helpful advice. :) 

Mario Gudelj

unread,
Dec 16, 2014, 11:02:09 AM12/16/14
to django...@googlegroups.com

Pgadmin3 is the bomb. Try that gui tool

Reply all
Reply to author
Forward
0 new messages