Learning django from "learning website development using django". In chapter 3, building a bookmark data model, I followed the instructions and code given except for--
from django.contrib.auth.models import User
class Bookmark(models.Model):
title = models.CharField(maxlength=200)
user = models.ForeignKey(User)
link = models.ForeignKey(Link)
where I changed
title = models.CharField(maxlength=200)
into
title = models.CharField(max_length=200)
as I was geting an error message. After that, I ran python manage.py syncdb, then, python manage.py sql bookmarks. When I checked http://localhost:8000/user/my_username, I get this error message:
Request Method: GET
Request URL: http://127.0.0.1:8000/user/j/
Django Version: 1.3
Exception Type: TemplateSyntaxError
Exception Value:
**Caught DatabaseError while rendering: no such column: bookmarks_bookmark.title**
Looking this up, I learned that sqlite3, the database i was using, cannot find bookmarks_bookmark.title. I went back into the book to make sure I have everything copied correctly, and I did except for that part that I changed (max_length). When I ran python manage.py sql bookmarks, it gave me--开发者_开发知识库
BEGIN;
CREATE TABLE "bookmarks_bookmark" (
"id" integer NOT NULL PRIMARY KEY,
"title" varchar(200) NOT NULL,
"user_id" integer NOT NULL REFERENCES
"auth_user" ("id"),
"link_id" integer NOT NULL REFERENCES
"bookmarks_link" ("id"),
);
CREATE TABLE "bookmarks_link" (
"id" integer NOT NULL PRIMARY KEY,
"url" varchar(200) NOT NULL UNIQUE
);
COMMIT;
How do I fix this? Thanks!
Manual deleting works.
sqlite3 yourdb.db
> drop table bookmarks_bookmark;
> .quit
cd yourpythonproj
python2 manage.py syncdb
python2 manage.py runserver
bash script
#!/bin/bash
sqlite3 ../yourdb.db 'drop table yourtable'
python2 manage.py syncdb
精彩评论