syncdb not creating columns in postgresql database

287 views
Skip to first unread message

Michael Ackerman

unread,
May 14, 2012, 11:54:35 AM5/14/12
to django...@googlegroups.com
Every time I edit a model and run syncdb, I get a database error telling me that the column doesn't exist.

#Error Message:
Environment:
Request Method: GET
Request URL: http://127.0.0.1:8000/tickets/2/

Django Version: 1.4
Python Version: 2.7.3
Installed Applications:
('django.contrib.auth',
 'django.contrib.contenttypes',
 'django.contrib.sessions',
 'django.contrib.sites',
 'django.contrib.messages',
 'django.contrib.staticfiles',
 'tickets',
 'django.contrib.admin')
Installed Middleware:
('django.middleware.common.CommonMiddleware',
 'django.contrib.sessions.middleware.SessionMiddleware',
 'django.middleware.csrf.CsrfViewMiddleware',
 'django.contrib.auth.middleware.AuthenticationMiddleware',
 'django.contrib.messages.middleware.MessageMiddleware')


Traceback:
File "/usr/local/lib/python2.7/dist-packages/django/core/handlers/base.py" in get_response
  111.                         response = callback(request, *callback_args, **callback_kwargs)
File "/usr/local/lib/python2.7/dist-packages/django/views/generic/base.py" in view
  48.             return self.dispatch(request, *args, **kwargs)
File "/usr/local/lib/python2.7/dist-packages/django/views/generic/base.py" in dispatch
  69.         return handler(request, *args, **kwargs)
File "/usr/local/lib/python2.7/dist-packages/django/views/generic/detail.py" in get
  98.         self.object = self.get_object()
File "/usr/local/lib/python2.7/dist-packages/django/views/generic/detail.py" in get_object
  49.             obj = queryset.get()
File "/usr/local/lib/python2.7/dist-packages/django/db/models/query.py" in get
  361.         num = len(clone)
File "/usr/local/lib/python2.7/dist-packages/django/db/models/query.py" in __len__
  85.                 self._result_cache = list(self.iterator())
File "/usr/local/lib/python2.7/dist-packages/django/db/models/query.py" in iterator
  291.         for row in compiler.results_iter():
File "/usr/local/lib/python2.7/dist-packages/django/db/models/sql/compiler.py" in results_iter
  763.         for rows in self.execute_sql(MULTI):
File "/usr/local/lib/python2.7/dist-packages/django/db/models/sql/compiler.py" in execute_sql
  818.         cursor.execute(sql, params)
File "/usr/local/lib/python2.7/dist-packages/django/db/backends/util.py" in execute
  40.             return self.cursor.execute(sql, params)
File "/usr/local/lib/python2.7/dist-packages/django/db/backends/postgresql_psycopg2/base.py" in execute
  52.             return self.cursor.execute(query, args)

Exception Type: DatabaseError at /tickets/2/
Exception Value: column tickets_ticket.picture does not exist
LINE 1: ...icket"."description", "tickets_ticket"."ranking", "tickets_t...
                                                             ^
I also noticed that when I run syncdb, It tells me that no new objects were installed.

But when i do python manage.py sql tickets, I get all my objects.
#python mange.py sql tickets
BEGIN;
CREATE TABLE "tickets_ticket" (
    "id" serial NOT NULL PRIMARY KEY,
    "title" varchar(100) NOT NULL,
    "date_created" timestamp with time zone NOT NULL,
    "description" text NOT NULL,
    "ranking" integer CHECK ("ranking" >= 0) NOT NULL,
    "picture" varchar(100) NOT NULL
)
;
COMMIT;

Is there a step I'm missing? I never had this problem while using sqlite, only in postgresql.
Any help is very much appreciated.



doniyor

unread,
May 14, 2012, 12:06:52 PM5/14/12
to django...@googlegroups.com
delete your app from INSTALLED_APPS and syncdb, AND list it again in INSTALLED_APPS and syncdb again.. 

if it doesnot work, do this: 

delete your db, then syncdb, then list your app in INSTALLED_APPS and syncdb again. 
Message has been deleted

kenneth gonsalves

unread,
May 15, 2012, 2:52:35 AM5/15/12
to django...@googlegroups.com
On Mon, 2012-05-14 at 09:06 -0700, doniyor wrote:
> delete your app from INSTALLED_APPS and syncdb, AND list it again in
> INSTALLED_APPS and syncdb again..
>
> if it doesnot work, do this:
>
> delete your db, then syncdb, then list your app in INSTALLED_APPS and
> syncdb again.

this is bad advice. Syncdb will not give effect to changes within a
model. You need to carry out the change manually, or use a migration
tool like south.
--
regards
Kenneth Gonsalves


Timothy Makobu

unread,
May 15, 2012, 4:44:40 AM5/15/12
to django...@googlegroups.com
You might want to look into using  South http://south.aeracode.org/ 

At first i thought it was cool, then I needed to alter a table with important data on it, and that's when I saw it's usefulness.




--
You received this message because you are subscribed to the Google Groups "Django users" group.
To post to this group, send email to django...@googlegroups.com.
To unsubscribe from this group, send email to django-users...@googlegroups.com.
For more options, visit this group at http://groups.google.com/group/django-users?hl=en.


doniyor

unread,
May 15, 2012, 6:22:29 AM5/15/12
to django...@googlegroups.com
sorry for bad advice.. i thought i could work,, 

Michael Ackerman

unread,
May 15, 2012, 9:39:16 AM5/15/12
to django...@googlegroups.com
Thanks for all the advice, I appreciate it.

--
You received this message because you are subscribed to the Google Groups "Django users" group.
To view this discussion on the web visit https://groups.google.com/d/msg/django-users/-/EGUFvATrjO8J.
Reply all
Reply to author
Forward
0 new messages