我按照django doc进行了民意调查。我有一个sqlite db' nameinfodb'。我想通过在线搜索姓氏来访问它。 我将models.py设置为
class Infotable(models.Model):
pid_text = models.CharField(max_length=200)
lname_text = models.CharField(max_length=200)
fname_text = models.CharField(max_length=200)
affs_text = models.CharField(max_length=2000)
idlist_text = models.CharField(max_length=2000)
def __str__(self):
return self
我将name.info.db复制到db.sqlite3所在的位置,更改了settings.py:
DATABASES = {
'default': {
'ENGINE': 'django.db.backends.sqlite3',
'NAME': os.path.join(BASE_DIR, 'name.info.db'),
}
}
然后我跑
python manage.py migrate
python manage.py makemigrations pidb
然后我检查了我是否正确
$ python manage.py sqlmigrate pidb 0001
BEGIN;
--
-- Create model Choice
--
CREATE TABLE "pidb_choice" ("id" integer NOT NULL PRIMARY KEY AUTOINCREMENT, "choice_text" varchar(200) NOT NULL, "votes" integer NOT NULL);
--
-- Create model Question
--
CREATE TABLE "pidb_question" ("id" integer NOT NULL PRIMARY KEY AUTOINCREMENT, "question_text" varchar(200) NOT NULL, "pub_date" datetime NOT NULL);
--
-- Add field question to choice
--
ALTER TABLE "pidb_choice" RENAME TO "pidb_choice__old";
CREATE TABLE "pidb_choice" ("id" integer NOT NULL PRIMARY KEY AUTOINCREMENT, "choice_text" varchar(200) NOT NULL, "votes" integer NOT NULL, "question_id" integer NOT NULL REFERENCES "pidb_question" ("id"));
INSERT INTO "pidb_choice" ("id", "question_id", "choice_text", "votes") SELECT "id", NULL, "choice_text", "votes" FROM "pidb_choice__old";
DROP TABLE "pidb_choice__old";
CREATE INDEX "pidb_choice_7aa0f6ee" ON "pidb_choice" ("question_id");
COMMIT;
我没有看到有关新数据库的任何信息,我看到的只是示例民意调查数据。我这里做错了吗?我需要做的就是连接到name.info.db,并按姓氏访问它。谢谢!
答案 0 :(得分:3)