2017-08-30 45 views
0

我正在編寫一個簡單的管理表單,但即使我已經完成了makemigration並遷移了很多次,它並沒有顯示更新,但沒有這樣的表的錯誤仍然顯示出來。OperationalError at/admin/Survey/intro/add/

回溯:

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',] 

謝謝!

+0

您是否檢查過數據庫以驗證表確實存在? – mathew

回答

0

如果Survey應用程序尚未進行任何遷移,那麼在進行遷移時您需要包含應用程序名稱。

python manage.py makemigrations Survey 
python manage.py migrate 

順便說一句,在Python/Django的通常的做法是命名您的應用程序survey,你的模型Intro,和你的類IntroFormIntroAdmin

相關問題