Using the django.contrib.auth User in my model - database error

405 views
Skip to first unread message

xTalisman

unread,
Jun 4, 2012, 3:49:23 AM6/4/12
to django...@googlegroups.com
Part of my application that uses the contrib,auth User 

from django.db import models
from django.contrib.auth.models import User

class Project(models.Model):

name = models.CharField(max_length=200)
startdate = models.DateField('Project Started')
enddate = models.DateField('Expected end date')
manager = models.ForeignKey(User,related_name="Expert")
users = models.ManyToManyField(User,related_name='project_users')

Then defined in admin.py

from coordination.models import *
from django.contrib import admin
from django.contrib.auth.models import User

class ProjectAdmin(admin.ModelAdmin):
fieldsets = [
(None, {'fields': ['name']}),
('People', {'fields': ['users'], 'classes' :['collapse']}),
('Date information', {'fields': ['startdate','enddate'] , 'classes' : ['collapse']}),]

admin.site.register(Project, ProjectAdmin)

I ran syncdb without a problem ,  then when I used the admin interface I get the following error :

Exception Type: DatabaseError at /admin/coordination/project/
Exception Value: no such column: coordination_project.manager_id

Kind regards , Jonathan



Request Method:GET
Request URL:http://localhost:8000/admin/coordination/project/
Django Version:1.4
Exception Type:DatabaseError
Exception Value:
no such column: coordination_project.manager_id
Exception Location:C:\Tools\Python2.7.2\lib\site-packages\django\db\backends\sqlite3\base.py in execute, line 337
Python Executable:C:\Tools\Python2.7.2\python.exe
Python Version:2.7.2

bruno desthuilliers

unread,
Jun 4, 2012, 4:23:33 AM6/4/12
to Django users
On Jun 4, 9:49 am, xTalisman <jonathan.talis...@gmail.com> wrote:
> I ran syncdb without a problem ,  then when I used the admin interface I
> get the following error :
>
> Exception Type: DatabaseError at /admin/coordination/project/
> Exception Value: no such column: coordination_project.manager_id
>

syncdb only creates the table if it doesn't yet exist in your db - it
will NOT modify an existing table. I guess you ran syncdb a first time
before adding the manager field ? if you either have to update your
schema manually or (better) use a schema-migration tool like South.

xTalisman

unread,
Jun 4, 2012, 4:27:44 AM6/4/12
to django...@googlegroups.com
Bruno , 
I thought so , so I deleted the the whole database (sqlite3) and ran the syncdb again , it created the tables as defined by django.contrib.auth and my application - but did not create the foreignkey columns manager and users.
Any ideas ?  

xTalisman

unread,
Jun 4, 2012, 5:01:16 AM6/4/12
to django...@googlegroups.com
Solved :
I dropped all the database tables (including the contib.auth ones) and ran syncdb, suddenly everything was fine. odd , but is working now .
Jonathan

bruno desthuilliers

unread,
Jun 4, 2012, 5:36:00 AM6/4/12
to Django users
On Jun 4, 11:01 am, xTalisman <jonathan.talis...@gmail.com> wrote:
> Solved :
> I dropped all the database tables (including the contib.auth ones) and ran
> syncdb, suddenly everything was fine. odd , but is working now .

Well, nice to know it works now, but yes this _is_ odd.

liuxi...@live.cn

unread,
Jun 10, 2012, 5:48:46 AM6/10/12
to Django users
how to drop all the database tables?

On 6月4日, 下午5时36分, bruno desthuilliers <bruno.desthuilli...@gmail.com>
wrote:

xTalisman

unread,
Jun 10, 2012, 6:49:36 AM6/10/12
to django...@googlegroups.com
I just used an sqlite3 and sqlitemanager which is a sqlite front-end , I am guessing it should not be too difficult to drop all tables with a script  too.

LiuXianghe

unread,
Jun 18, 2012, 9:20:41 PM6/18/12
to django...@googlegroups.com



Date: Sun, 10 Jun 2012 03:49:36 -0700
From: jonathan...@gmail.com
To: django...@googlegroups.com
Subject: Re: Using the django.contrib.auth User in my model - database error


I just used an sqlite3 and sqlitemanager which is a sqlite front-end , I am guessing it should not be too difficult to drop all tables with a script  too.

On Sunday, June 10, 2012 12:48:46 PM UTC+3, liuxi...@live.cn wrote:
how to drop all the database tables?

On 6锟斤拷4锟斤拷, 锟斤拷锟斤拷5时36锟斤拷, bruno desthuilliers <bruno.desthuilli...@gmail.com>
wrote:
> On Jun 4, 11:01 am, xTalisman <jonathan.talis...@gmail.com> wrote:
>
> > Solved :
> > I dropped all the database tables (including the contib.auth ones) and ran
> > syncdb, suddenly everything was fine. odd , but is working now .
>
> Well, nice to know it works now, but yes this _is_ odd.

--
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/-/EZcFrrEUGyQJ.
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.

thank you ,but it's not to the point. All that messed me round is just when i syncdb the datebase, the fields I've just added is not actually built in the .db file. So I delete the .db file and syncdb again, and it's all done.
Reply all
Reply to author
Forward
0 new messages