异常值:没有这样的表:example_post

时间:2017-09-15 20:30:28

标签: python django

我在尝试https://github.com/zhebrak/django-statsy

中的exemple文件时遇到了一些问题
OperationalError at /
no such table: example_post
Request Method: GET
Request URL:    http://localhost:8000/
Django Version: 1.11.5
Exception Type: OperationalError
Exception Value: no such table: example_post
Exception Location: /home/jeremie/.virtualenvs/statsy/local/lib/python2.7/site-packages/django/db/models/sql/compiler.py in execute_sql, line 894
Python Executable:  /home/jeremie/.virtualenvs/statsy/bin/python
Python Version: 2.7.12
Python Path:    
['/home/jeremie/django-statsy',
 '/home/jeremie/.virtualenvs/statsy/lib/python2.7',
 '/home/jeremie/.virtualenvs/statsy/lib/python2.7/plat-x86_64-linux-gnu',
 '/home/jeremie/.virtualenvs/statsy/lib/python2.7/lib-tk',
 '/home/jeremie/.virtualenvs/statsy/lib/python2.7/lib-old',
 '/home/jeremie/.virtualenvs/statsy/lib/python2.7/lib-dynload',
 '/usr/lib/python2.7',
 '/usr/lib/python2.7/plat-x86_64-linux-gnu',
 '/usr/lib/python2.7/lib-tk',
 '/home/jeremie/.virtualenvs/statsy/local/lib/python2.7/site-packages',
 '/home/jeremie/.virtualenvs/statsy/lib/python2.7/site-packages',
 '/home/jeremie/django-statsy']
Server time:    Fri, 15 Sep 2017 15:13:34 -0500

这是我到目前为止所做的:

  1. git clone https://github.com/zhebrak/django-statsy.git
  2. mkvirtualenv statsy
  3. cd django-statsy
  4. workon statsy
  5. pip install -r requirements.txt
  6. python manage.py makemigrations
  7. python manage.py migrate
  8. python manage.py runserver
  9. 我只想进入example文件内部以查看结果类型并测试应用程序本身。为什么我有这个问题?如果我使用Django 1.10python 2.7

    在项目中工作,您是否推荐此应用?

    更新

    ┌─╼ [~/django-statsy]
    └────╼ python2.7 manage.py makemigrations example
    Migrations for 'example':
      example/migrations/0001_initial.py
        - Create model Post
    ┌─╼ [~/django-statsy]
    └────╼ python2.7 manage.py migrate example
    Operations to perform:
      Apply all migrations: example
    Running migrations:
      Applying example.0001_initial... OK
    

    以下是我运行localhost:8000image

    时的结果

    我怎样才能测出给出的例子?

1 个答案:

答案 0 :(得分:0)

根据您在评论中的回复,看起来您还没有创建example_post数据库表。您需要将example添加到设置文件中的INSTALLED_APPS列表中,然后运行数据库迁移过程:

./manage.py makemigrations
./manage.py migrate

如果example应用程序不在INSTALLED_APPS中,则无法创建数据库迁移文件,因此无法创建表格。