0

I created app on pyhonanywhere.com, but cant execute that command: python manage.py migrate

If i try do it, appear error:

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

I use Python 3.4 and Django 1.10. In localhost site works fine. What am i must do?

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='Телефон')
Антон Игин
  • 195
  • 1
  • 1
  • 12
  • Can you show the output of `python manage.py showmigrations`, and show us the faulty migration file? – Raphaël Gomès Feb 03 '17 at 12:17
  • 1
    You are hitting [this problem](http://stackoverflow.com/questions/37031579/django-migrations-fail-during-django-initialization/37032654#37032654). In particular, the traceback is telling you that one of your forms in `home/oriflame/site_oriflame/main_site/forms.py` is trying to fetch from the database when the module is imported. This causes an error in your new environment, because the table has not been created yet. – Alasdair Feb 03 '17 at 12:27
  • I had the same problem and I solved it [this way](http://stackoverflow.com/questions/39535983/migration-clashes-with-forms-py). – albar Feb 03 '17 at 13:07
  • @RaphaëlGomès, 'python manage.py showmigrations' shows the same error. I don't know what specific file needs to lose. I suppose the problem with a model field, then i need to show models.py, right? – Антон Игин Feb 03 '17 at 13:11
  • @Alasdair, okay, but how fix it? I quess, that's because in forms.py i do request: sponsor_list = Sponsor.objects.all() Maybe migrate is failed, because i don't have that objects in directory? – Антон Игин Feb 03 '17 at 13:17
  • @АнтонИгин: please update your post with your `forms.py`. – Raphaël Gomès Feb 03 '17 at 13:17
  • @RaphaëlGomès already did. – Антон Игин Feb 03 '17 at 13:25
  • 1
    @АнтонИгин Well there you go, you are running database fetches at module level. Wrap those lines in a function or method and you should be good to go. Do you see what you did wrong? – Raphaël Gomès Feb 03 '17 at 13:27
  • @RaphaëlGomès i quess i need create function in forms.py: def list_objects(x): return x.objects.all() sponsor_list = list_objects(Sponsor) That construction instead of direct query will solve my problem, right? – Антон Игин Feb 03 '17 at 13:57
  • 1
    @АнтонИгин: see Alasdair's great answer. Although I would suggest getting a better name for your function, since "get_leader" implies a singular object, but your return value is a list. – Raphaël Gomès Feb 03 '17 at 13:58

1 Answers1

1

You should not be generating the list leader in the module. Apart from problems with running migrations, the list will be generated only once when the server starts, and will not be updated when new sponsors are added to the database.

You could wrap the code in a function, for example:

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

Since you have moved the sponsor_list variable inside the get_leader method, you'll have to update you sponsor field, e.g change it to:

sponsor = forms.ModelChoiceField(label='Спонсор',queryset=Sponsor.objects.all(), empty_label='---', widget=forms.Select(attrs={'class':'ftrmail'}))

Then change your code that uses leader to call get_leader().

You might need to make further changes - since you haven't shown where you use the leader variable it's not possible to say.

Alasdair
  • 298,606
  • 55
  • 578
  • 516