我在pyhonanywhere.com上创建了应用程序,但无法执行该命令: python manage.py migrate
如果我尝试这样做,则会出现错误:
Traceback (most recent call last):
File "/home/oriflame/site_oriflame/myvenv/lib/python3.4/site-packages/django/db/backends/utils.py", line 64, in execute
return self.cursor.execute(sql, params)
File "/home/oriflame/site_oriflame/myvenv/lib/python3.4/site-packages/django/db/backends/sqlite3/base.py", line 337, in execute
return Database.Cursor.execute(self, query, params)
sqlite3.OperationalError: no such table: main_site_sponsor
The above exception was the direct cause of the following exception:
Traceback (most recent call last):
File "manage.py", line 22, in <module>
execute_from_command_line(sys.argv)
File "/home/oriflame/site_oriflame/myvenv/lib/python3.4/site-packages/django/core/management/__init__.py", line 367, in execute_from_command_line
utility.execute()
File "/home/oriflame/site_oriflame/myvenv/lib/python3.4/site-packages/django/core/management/__init__.py", line 359, in execute
self.fetch_command(subcommand).run_from_argv(self.argv)
File "/home/oriflame/site_oriflame/myvenv/lib/python3.4/site-packages/django/core/management/base.py", line 294, in run_from_argv
self.execute(*args, **cmd_options)
File "/home/oriflame/site_oriflame/myvenv/lib/python3.4/site-packages/django/core/management/base.py", line 342, in execute
self.check()
File "/home/oriflame/site_oriflame/myvenv/lib/python3.4/site-packages/django/core/management/base.py", line 374, in check
include_deployment_checks=include_deployment_checks,
File "/home/oriflame/site_oriflame/myvenv/lib/python3.4/site-packages/django/core/management/commands/migrate.py", line 62, in _run_checks
issues.extend(super(Command, self)._run_checks(**kwargs))
File "/home/oriflame/site_oriflame/myvenv/lib/python3.4/site-packages/django/core/management/base.py", line 361, in _run_checks
return checks.run_checks(**kwargs)
File "/home/oriflame/site_oriflame/myvenv/lib/python3.4/site-packages/django/conf/urls/__init__.py", line 50, in include
File "/home/oriflame/site_oriflame/myvenv/lib/python3.4/site-packages/django/core/checks/registry.py", line 81, in run_checks
new_errors = check(app_configs=app_configs)
File "/home/oriflame/site_oriflame/myvenv/lib/python3.4/site-packages/django/core/checks/urls.py", line 14, in check_url_config
return check_resolver(resolver)
File "/home/oriflame/site_oriflame/myvenv/lib/python3.4/site-packages/django/core/checks/urls.py", line 24, in check_resolver
for pattern in resolver.url_patterns:
File "/home/oriflame/site_oriflame/myvenv/lib/python3.4/site-packages/django/utils/functional.py", line 35, in __get__
res = instance.__dict__[self.name] = self.func(instance)
File "/home/oriflame/site_oriflame/myvenv/lib/python3.4/site-packages/django/urls/resolvers.py", line 313, in url_patterns
patterns = getattr(self.urlconf_module, "urlpatterns", self.urlconf_module)
File "/home/oriflame/site_oriflame/myvenv/lib/python3.4/site-packages/django/utils/functional.py", line 35, in __get__
res = instance.__dict__[self.name] = self.func(instance)
File "/home/oriflame/site_oriflame/myvenv/lib/python3.4/site-packages/django/urls/resolvers.py", line 306, in urlconf_module
return import_module(self.urlconf_name)
File "/home/oriflame/site_oriflame/myvenv/lib/python3.4/importlib/__init__.py", line 109, in import_module
return _bootstrap._gcd_import(name[level:], package, level)
File "<frozen importlib._bootstrap>", line 2254, in _gcd_import
File "<frozen importlib._bootstrap>", line 2237, in _find_and_load
File "<frozen importlib._bootstrap>", line 2226, in _find_and_load_unlocked
File "<frozen importlib._bootstrap>", line 1200, in _load_unlocked
File "<frozen importlib._bootstrap>", line 1129, in _exec
File "<frozen importlib._bootstrap>", line 1471, in exec_module
File "<frozen importlib._bootstrap>", line 321, in _call_with_frames_removed
File "/home/oriflame/site_oriflame/project_oriflame/urls.py", line 30, in <module>
url(r'', include('main_site.urls')),
File "/home/oriflame/site_oriflame/myvenv/lib/python3.4/site-packages/django/conf/urls/__init__.py", line 50, in include
urlconf_module = import_module(urlconf_module)
File "/home/oriflame/site_oriflame/myvenv/lib/python3.4/importlib/__init__.py", line 109, in import_module
return _bootstrap._gcd_import(name[level:], package, level)
File "<frozen importlib._bootstrap>", line 2254, in _gcd_import
File "<frozen importlib._bootstrap>", line 2237, in _find_and_load
File "<frozen importlib._bootstrap>", line 2226, in _find_and_load_unlocked
File "<frozen importlib._bootstrap>", line 1200, in _load_unlocked
File "<frozen importlib._bootstrap>", line 1129, in _exec
File "<frozen importlib._bootstrap>", line 1471, in exec_module
File "<frozen importlib._bootstrap>", line 321, in _call_with_frames_removed
File "/home/oriflame/site_oriflame/main_site/urls.py", line 20, in <module>
from . import views
File "/home/oriflame/site_oriflame/main_site/views.py", line 13, in <module>
from .forms import Call_Form, Registration
File "/home/oriflame/site_oriflame/main_site/forms.py", line 8, in <module>
for value in sponsor_list:
File "/home/oriflame/site_oriflame/myvenv/lib/python3.4/site-packages/django/db/models/query.py", line 256, in __iter__
self._fetch_all()
File "/home/oriflame/site_oriflame/myvenv/lib/python3.4/site-packages/django/db/models/query.py", line 1087, in _fetch_all
self._result_cache = list(self.iterator())
File "/home/oriflame/site_oriflame/myvenv/lib/python3.4/site-packages/django/db/models/query.py", line 54, in __iter__
results = compiler.execute_sql()
File "/home/oriflame/site_oriflame/myvenv/lib/python3.4/site-packages/django/db/models/sql/compiler.py", line 835, in execute_sql
cursor.execute(sql, params)
File "/home/oriflame/site_oriflame/myvenv/lib/python3.4/site-packages/django/db/backends/utils.py", line 79, in execute
return super(CursorDebugWrapper, self).execute(sql, params)
File "/home/oriflame/site_oriflame/myvenv/lib/python3.4/site-packages/django/db/backends/utils.py", line 64, in execute
return self.cursor.execute(sql, params)
File "/home/oriflame/site_oriflame/myvenv/lib/python3.4/site-packages/django/db/utils.py", line 94, in __exit__
six.reraise(dj_exc_type, dj_exc_value, traceback)
File "/home/oriflame/site_oriflame/myvenv/lib/python3.4/site-packages/django/utils/six.py", line 685, in reraise
raise value.with_traceback(tb)
File "/home/oriflame/site_oriflame/myvenv/lib/python3.4/site-packages/django/db/backends/utils.py", line 64, in execute
return self.cursor.execute(sql, params)
File "/home/oriflame/site_oriflame/myvenv/lib/python3.4/site-packages/django/db/backends/sqlite3/base.py", line 337, in execute
return Database.Cursor.execute(self, query, params)
django.db.utils.OperationalError: no such table: main_site_sponsor
我使用Python 3.4和Django 1.10。在localhost网站工作正常。 我该怎么办?
UPD:forms.py
#!/usr/bin/python
# -*- coding: utf-8 -*-
from django import forms
import datetime
from .models import Sponsor
sponsor_list = Sponsor.objects.all()
leader=[]
for value in sponsor_list:
current_leader = value.name+' '+value.surname+' '+value.middle+' ('+str(value.code_number)+')'
leader.append(current_leader)
class Registration(forms.Form):
email = forms.CharField( label='', max_length=50, widget=forms.TextInput(attrs={'placeholder': 'E-mail', 'class':'ftrmail'}))
password = forms.CharField( label='', max_length=50, widget=forms.TextInput(attrs={'placeholder': 'Пароль', 'class':'ftrmail'}))
lastname = forms.CharField( label='', max_length=50, widget=forms.TextInput(attrs={'placeholder': 'Иванов', 'class':'ftrmail'}))
name = forms.CharField(label='', max_length=50, widget=forms.TextInput(attrs={'placeholder': 'Иван', 'class':'ftrmail'}))
middlename = forms.CharField(label='', max_length=50, widget=forms.TextInput(attrs={'placeholder': 'Иванович', 'class':'ftrmail'}))
passport = forms.IntegerField(label='', widget=forms.TextInput(attrs={'placeholder': 'Серия и номер паспорта', 'class':'ftrmail'}))
birthday = forms.DateField(label='', widget=forms.DateInput(attrs={'placeholder': 'День рождения (ДД/ММ/ГГГГ)', 'class':'ftrmail', 'type':'date'}))
telephone = forms.IntegerField(label='', widget=forms.TextInput(attrs={'placeholder': '+7 XXX XXX XX XX', 'class':'ftrmail'}))
region = forms.CharField(label='', max_length=50, widget=forms.TextInput(attrs={'placeholder': 'Область','class':'ftrmail'}))
index = forms.IntegerField(label='', widget=forms.TextInput(attrs={'placeholder': 'Почтовый индекс','class':'ftrmail'}))
district = forms.CharField(label='', max_length=50, widget=forms.TextInput(attrs={'placeholder': 'Район','class':'ftrmail'}))
town = forms.CharField(label='', max_length=50, widget=forms.TextInput(attrs={'placeholder': 'Город','class':'ftrmail'}))
street = forms.CharField(label='', max_length=50, widget=forms.TextInput(attrs={'placeholder': 'Улица','class':'ftrmail'}))
number = forms.CharField(label='', max_length=50, widget=forms.TextInput(attrs={'placeholder': 'Номер дома и квартиры','class':'ftrmail'}))
sponsor = forms.ModelChoiceField(label='Спонсор',queryset=sponsor_list, empty_label='---', widget=forms.Select(attrs={'class':'ftrmail'}))
class Call_Form(forms.Form):
name = forms.CharField(label='Имя', max_length=50)
telephone = forms.IntegerField(label='Телефон')
答案 0 :(得分:1)
您不应该在模块中生成列表restrict
。除了运行迁移的问题之外,列表将仅在服务器启动时生成一次,并且在将新的赞助商添加到数据库时不会更新。
您可以将代码包装在函数中,例如:
leader
由于您已在def get_leader():
sponsor_list = Sponsor.objects.all()
leader=[]
for value in sponsor_list:
current_leader = value.name+' '+value.surname+' '+value.middle+' ('+str(value.code_number)+')'
leader.append(current_leader)
return leader
方法中移动了sponsor_list
变量,因此您必须更新get_leader
字段,例如将其更改为:
sponsor
然后更改使用sponsor = forms.ModelChoiceField(label='Спонсор',queryset=Sponsor.objects.all(), empty_label='---', widget=forms.Select(attrs={'class':'ftrmail'}))
的代码来调用leader
。
您可能需要进行进一步的更改 - 因为您还没有显示使用get_leader()
变量的位置,因此无法说明。