5.9 Creating Our Production Database with migrate
parent
fd4dcc2425
commit
a9bf5ed847
|
@ -390,3 +390,36 @@ def home_page(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
|
||||
<table id="id_list_table">
|
||||
{% for item in items %}
|
||||
<tr><td>{{ forloop.counter }}: {{ item.text }}</td></tr>
|
||||
{% endfor %}
|
||||
</table>
|
||||
```
|
||||
|
||||
* 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
|
||||
```
|
Loading…
Reference in New Issue