2
我跟着django文檔並通過了民意調查的例子。我有一個sqlite數據庫'nameinfodb'。我想通過在線查找姓氏來訪問它。 我設置models.py作爲在django中設置數據庫
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,並按姓氏訪問它。謝謝!