From a9bf5ed847e94e953a631cf89c79be66b8fe5f61 Mon Sep 17 00:00:00 2001 From: JasonHomeWorkstationUbuntu Date: Mon, 9 Nov 2020 14:57:50 +1100 Subject: [PATCH] 5.9 Creating Our Production Database with migrate --- textbook/chap5.md | 33 +++++++++++++++++++++++++++++++++ 1 file changed, 33 insertions(+) diff --git a/textbook/chap5.md b/textbook/chap5.md index d2e5913..6e6760d 100644 --- a/textbook/chap5.md +++ b/textbook/chap5.md @@ -389,4 +389,37 @@ def home_page(request): return render(request=request, template_name='home.html', context={'items': items}) # pass items into template using render +``` + +## 5.9 Creating Our Production Database with migrate + +If use FT `functional_tests.py` to verify, will return an error `no such table: lists_item` + +Why? Because Django creates test database for unit tests, this database cannot be used by FT. + +Migrate the database using `python manage.py migrate` + +`functional_tests.py` Test Result: + +``` +AssertionError: '2: Use peacock feathers to make a fly' not found in ['1: Buy peacock feathers', '1: Use peacock feathers to make a fly'] +``` + +* Problem: need to get list numbering right. +* Solution: using Django template tag, `forloop.counter` in template `home.html` + +```html + + {% for item in items %} + + {% endfor %} +
{{ forloop.counter }}: {{ item.text }}
+``` + +* Remaining problem: database are polluted by items from previous FT round. +* ANS: Find a automated way of clear database after each FT + +``` +rm db.sqlite3 +python manage.py migrate --noinput ``` \ No newline at end of file