/ admin / Survey / intro / add /的OperationalError

时间:2017-08-30 19:27:59

标签: python django django-models django-admin

我正在写一个简单的管理表单,但是没有这样的表的错误一直显示,即使我已经完成了makemigration并且多次迁移它没有显示更新。

回溯:

File "C:\Python34\lib\site-packages\django\db\backends\utils.py" in execute 65. return self.cursor.execute(sql, params)
File "C:\Python34\lib\site-packages\django\db\backends\sqlite3\base.py" in execute 328. return Database.Cursor.execute(self, query, params)
The above exception (no such table: Survey_intro) was the direct cause of the following exception:
File "C:\Python34\lib\site-packages\django\core\handlers\exception.py" in inner 41. response = get_response(request)
File "C:\Python34\lib\site-packages\django\core\handlers\base.py" in _get_response 187. response = self.process_exception_by_middleware(e, request)
File "C:\Python34\lib\site-packages\django\core\handlers\base.py" in _get_response 185. response = wrapped_callback(request, *callback_args, **callback_kwargs)
File "C:\Python34\lib\site-packages\django\contrib\admin\options.py" in wrapper 551. return self.admin_site.admin_view(view)(*args, **kwargs)
File "C:\Python34\lib\site-packages\django\utils\decorators.py" in _wrapped_view 149. response = view_func(request, *args, **kwargs)
File "C:\Python34\lib\site-packages\django\views\decorators\cache.py" in _wrapped_view_func 57. response = view_func(request, *args, **kwargs)
File "C:\Python34\lib\site-packages\django\contrib\admin\sites.py" in inner 224. return view(request, *args, **kwargs)
File "C:\Python34\lib\site-packages\django\contrib\admin\options.py" in add_view 1508. return self.changeform_view(request, None, form_url, extra_context)
File "C:\Python34\lib\site-packages\django\utils\decorators.py" in _wrapper 67. return bound_func(*args, **kwargs)
File "C:\Python34\lib\site-packages\django\utils\decorators.py" in _wrapped_view 149. response = view_func(request, *args, **kwargs)
File "C:\Python34\lib\site-packages\django\utils\decorators.py" in bound_func 63. return func.get(self, type(self))(*args2, **kwargs2)
File "C:\Python34\lib\site-packages\django\contrib\admin\options.py" in changeform_view 1408. return self._changeform_view(request, object_id, form_url, extra_context)
File "C:\Python34\lib\site-packages\django\contrib\admin\options.py" in _changeform_view 1448. self.save_model(request, new_object, form, not add)
File "C:\Python34\lib\site-packages\django\contrib\admin\options.py" in save_model 979. obj.save()
File "C:\Python34\lib\site-packages\django\db\models\base.py" in save 806. force_update=force_update, update_fields=update_fields)
File "C:\Python34\lib\site-packages\django\db\models\base.py" in save_base 836. updated = self._save_table(raw, cls, force_insert, force_update, using, update_fields)
File "C:\Python34\lib\site-packages\django\db\models\base.py" in _save_table 922. result = self._do_insert(cls._base_manager, using, fields, update_pk, raw)
File "C:\Python34\lib\site-packages\django\db\models\base.py" in _do_insert 961. using=using, raw=raw)
File "C:\Python34\lib\site-packages\django\db\models\manager.py" in manager_method 85. return getattr(self.get_queryset(), name)(*args, **kwargs)
File "C:\Python34\lib\site-packages\django\db\models\query.py" in _insert 1061. return query.get_compiler(using=using).execute_sql(return_id)
File "C:\Python34\lib\site-packages\django\db\models\sql\compiler.py" in execute_sql 1099. cursor.execute(sql, params)
File "C:\Python34\lib\site-packages\django\db\backends\utils.py" in execute 80. return super(CursorDebugWrapper, self).execute(sql, params)
File "C:\Python34\lib\site-packages\django\db\backends\utils.py" in execute 65. return self.cursor.execute(sql, params)
File "C:\Python34\lib\site-packages\django\db\utils.py" in exit 94. six.reraise(dj_exc_type, dj_exc_value, traceback)
File "C:\Python34\lib\site-packages\django\utils\six.py" in reraise 685. raise value.with_traceback(tb)
File "C:\Python34\lib\site-packages\django\db\backends\utils.py" in execute 65. return self.cursor.execute(sql, params)
File "C:\Python34\lib\site-packages\django\db\backends\sqlite3\base.py" in execute 328. return Database.Cursor.execute(self, query, params)

admin.py

class introAdmin(admin.ModelAdmin):
   form = introForm

admin.site.register(intro, introAdmin) 

models.py

class intro(models.Model):
EDUCATION_CHOICES = (
                    ('1','1'),
                    ('2','2'),
                    ('3','3'),
                    ('4','4'),
                    ('G','Graduate'),
                    ('P','Professor')
                    )
SEX_CHOICES = (
           ('M','Male'),
           ('F','Female'),
           )
name = models.CharField(max_length = 10)
education = models.CharField(max_length = 1,choices = EDUCATION_CHOICES)
sex = models.CharField(max_length = 1, choices = SEX_CHOICES)

forms.py

class introForm(forms.ModelForm):
class Meta:
    model = intro
    fields = ['name','education','sex',]

谢谢!

1 个答案:

答案 0 :(得分:0)

如果Survey应用尚未进行任何迁移,则您需要在进行迁移时包含应用名称。

python manage.py makemigrations Survey 
python manage.py migrate

顺便说一下,Python / Django中常用的方法是命名您的应用survey,您的模型Intro以及您的课程IntroFormIntroAdmin