jjgod
unread,Apr 2, 2009, 1:02:28 PM4/2/09Sign in to reply to author
Sign in to forward
You do not have permission to delete messages in this group
Either email addresses are anonymous for this group or you need the view member email addresses permission to view the original message
to Django users
Hi,
I'm running Django version 1.1 beta 1 SVN-10368.
I'm having a problem trying to a ManyToMany field to an existing
model.
In an application called "videos", I created a models.py like this:
from django.db import models
class Speaker(models.Model):
name = models.CharField(max_length=200)
localized_name = models.CharField(max_length=200)
bio = models.TextField()
class Video(models.Model):
title = models.CharField(max_length=200)
localized_title = models.CharField(max_length=200)
description = models.TextField()
filmed_on = models.DateField('date filmed')
video_url = models.URLField(verify_exists=False)
subtitle_url = models.URLField(verify_exists=False)
then I add
speakers = models.ManyToManyField("Speaker")
to the end of Video class.
when I run "python manage.py sql videos", it returns:
BEGIN;
CREATE TABLE "videos_speaker" (
"id" integer NOT NULL PRIMARY KEY,
"name" varchar(200) NOT NULL,
"localized_name" varchar(200) NOT NULL,
"bio" text NOT NULL
)
;
CREATE TABLE "videos_video" (
"id" integer NOT NULL PRIMARY KEY,
"title" varchar(200) NOT NULL,
"localized_title" varchar(200) NOT NULL,
"description" text NOT NULL,
"filmed_on" date NOT NULL,
"video_url" varchar(200) NOT NULL,
"subtitle_url" varchar(200) NOT NULL
)
;
CREATE TABLE "videos_video_speakers" (
"id" integer NOT NULL PRIMARY KEY,
"video_id" integer NOT NULL REFERENCES "videos_video" ("id"),
"speaker_id" integer NOT NULL REFERENCES "videos_speaker" ("id"),
UNIQUE ("video_id", "speaker_id")
)
;
COMMIT;
which seems to be fine for me. Then I run "python manage.py syncdb",
yet it does not create any new table for me, and when I try to look
into the database generated with sqlite3 <dbname>, it shows:
sqlite> .tables
auth_group django_admin_log
auth_group_permissions django_content_type
auth_message django_session
auth_permission django_site
auth_user videos_speaker
auth_user_groups videos_video
auth_user_user_permissions
which apparently does not have the last table described in "python
manage.py sql videos". Then I try to add a video object in admin page,
it gives me error page like this:
OperationalError at /admin/videos/video/1/
no such table: videos_video_speakers
I'm fairly new to Django, so I really wish to know if I missed
something. Thanks in advance.