Форум сайта python.su
from django.db import models
class Category(models.Model):
title = models.CharField(maxlength=64)
review = models.TextField()
ord_number = models.IntegerField()
class Admin:
pass
class Publication(models.Model):
title = models.CharField(maxlength=255)
review = models.TextField()
content = models.TextField()
author = models.CharField(maxlength=255)
category = models.ForeignKey(Category)
date = models.DateField()
url = models.URLField()
class Admin:
pass
Когда тыкаю в админке Publications, то возникает ошибка:
OperationalError at /admin/publications/publication/
(1054, “Unknown column ‘publications_publication.category_id’ in ‘field list’”)
P.S. Запрос был такой при sqlall:
C:\Server\www\p>python manage.py sqlall publications
BEGIN;
CREATE TABLE `publications_category` (
`id` integer AUTO_INCREMENT NOT NULL PRIMARY KEY,
`title` varchar(64) NOT NULL,
`review` longtext NOT NULL,
`ord_number` integer NOT NULL
);
CREATE TABLE `publications_publication` (
`id` integer AUTO_INCREMENT NOT NULL PRIMARY KEY,
`title` varchar(255) NOT NULL,
`review` longtext NOT NULL,
`content` longtext NOT NULL,
`author` varchar(255) NOT NULL,
`category_id` integer NOT NULL REFERENCES `publications_category` (`id`),
`date` date NOT NULL,
`url` varchar(200) NOT NULL
);
CREATE INDEX publications_publication_category_id ON `publications_publication` (`category_id`);
COMMIT;
Офлайн
OperationalError at /admin/publications/publication/add/
(1054, “Unknown column ‘category_id’ in ‘field list’”) Это когда добавляю запись.
Офлайн
mysql> select * from publications_publication;
+—-+————————+———-+———+——–+————+——————+
| id | title | review | content | author | date | url |
+—-+————————+———-+———+——–+————+——————+
| 1 | models.ManyToManyField | rtretgre | rwerew | were | 2007-05-02 | http://HungeR.ru |
| 2 | models.ManyToManyField | rtretgre | rwerew | were | 2007-05-02 | http://HungeR.ru |
| 3 | 56765756756 | rtretgre | rwerew | were | 2007-05-02 | http://HungeR.ru |
+—-+————————+———-+———+——–+————+——————+
3 rows in set (0.00 sec)
мм, а тут нету поля models.ForeignKey(Category) =\
Офлайн
I tried to use sqlite3 instead of mysql, and it starts work.
But I need mysql, how to make this code work with it?
Офлайн
какая верси django, trunk или тарбол?
Попробуй поле ForeignKey сделать первым в модели.
Офлайн
дижанго версии 0.96, пакетом ставил с сайта.
А если она будет первая, то просто в запросе изменится порядок =\
Офлайн