Django no such table after migrations after cloning from git

Мой первый вопрос здесь и я новичок, так что извините, если я сделал какую-либо ошибку.

Используемая среда: ubuntu 18, python 2.7, django версии 1.8.2

Я переношу рабочую среду с одного ПК на другой путем клонирования git-репо. Но на новом ПК я получаю ошибку: django.db.utils.OperationalError: no such table: tableName для всех команд типа python manage.py runserver/makemigrations/migrate/flush etc

Я потратил целый день на поиски решения. Ссылка с той же проблемой:

django.db.utils.OperationalError: no such table: price_category AFTER GIT CLONE

Ошибка миграции в django: "no such table"

и многое другое

Общее решение, приведенное во всех этих ответах:

  1. удалите все файлы миграции, кроме init.py (вопрос: должен ли я также сохранить init.pyc?)
  2. удалите базу данных
  3. запустите makemigrations/migrate

Я сделал первое. Для второго google говорит удалить файл .sqlite3, но я не смог найти его. В settings.py

DATABASES = {
    'default': {
        'ENGINE': 'django.db.backends.sqlite3',
        'NAME': 'IITMSAT_Telecommands_database',
    }
}

Структура папок (я удалил то, что отмечено красными линиями)

Ошибка:

  File "manage.py", line 24, in <module>
    execute_from_command_line(sys.argv)
  File "/usr/local/lib/python2.7/dist-packages/django/core/management/__init__.py", line 338, in execute_from_command_line
    utility.execute()
  File "/usr/local/lib/python2.7/dist-packages/django/core/management/__init__.py", line 312, in execute
    django.setup()
  File "/usr/local/lib/python2.7/dist-packages/django/__init__.py", line 18, in setup
    apps.populate(settings.INSTALLED_APPS)
  File "/usr/local/lib/python2.7/dist-packages/django/apps/registry.py", line 108, in populate
    app_config.import_models(all_models)
  File "/usr/local/lib/python2.7/dist-packages/django/apps/config.py", line 198, in import_models
    self.models_module = import_module(models_module_name)
  File "/usr/lib/python2.7/importlib/__init__.py", line 37, in import_module
    __import__(name)
  File "/home/spacelab/groundstationsoftware/MCS/Telemetry/models.py", line 304, in <module>
    class Short_Beacon(models.Model):
  File "/home/spacelab/groundstationsoftware/MCS/Telemetry/models.py", line 308, in Short_Beacon
    session                     = models.IntegerField(default=get_current_sub_pass())
  File "/home/spacelab/groundstationsoftware/MCS/Telecommands/models.py", line 32, in get_current_sub_pass
    print(Satellite_Pass.objects.filter(passing_now=1))
  File "/usr/local/lib/python2.7/dist-packages/django/db/models/query.py", line 138, in __repr__
    data = list(self[:REPR_OUTPUT_SIZE + 1])
  File "/usr/local/lib/python2.7/dist-packages/django/db/models/query.py", line 162, in __iter__
    self._fetch_all()
  File "/usr/local/lib/python2.7/dist-packages/django/db/models/query.py", line 965, in _fetch_all
    self._result_cache = list(self.iterator())
  File "/usr/local/lib/python2.7/dist-packages/django/db/models/query.py", line 238, in iterator
    results = compiler.execute_sql()
  File "/usr/local/lib/python2.7/dist-packages/django/db/models/sql/compiler.py", line 840, in execute_sql
    cursor.execute(sql, params)
  File "/usr/local/lib/python2.7/dist-packages/django/db/backends/utils.py", line 79, in execute
    return super(CursorDebugWrapper, self).execute(sql, params)
  File "/usr/local/lib/python2.7/dist-packages/django/db/backends/utils.py", line 64, in execute
    return self.cursor.execute(sql, params)
  File "/usr/local/lib/python2.7/dist-packages/django/db/utils.py", line 97, in __exit__
    six.reraise(dj_exc_type, dj_exc_value, traceback)
  File "/usr/local/lib/python2.7/dist-packages/django/db/backends/utils.py", line 64, in execute
    return self.cursor.execute(sql, params)
  File "/usr/local/lib/python2.7/dist-packages/django/db/backends/sqlite3/base.py", line 318, in execute
    return Database.Cursor.execute(self, query, params)
django.db.utils.OperationalError: no such table: Telecommands_satellite_pass

models.py из папки telecommands

папка миграции в телекомандах:

0001_initial.py

0002_auto_20161229_1325.py

from __future__ import unicode_literals

from django.db import models, migrations
import django.utils.timezone


class Migration(migrations.Migration):

    dependencies = [
        ('Telecommands', '0001_initial'),
    ]

    operations = [
        migrations.AddField(
            model_name='tc_sent_packet',
            name='error_status',
            field=models.CharField(default=b'Not yet received', max_length=300, blank=True),
        ),
        migrations.AlterField(
            model_name='long_beacon',
            name='recieved_on',
            field=models.DateTimeField(default=django.utils.timezone.now),
        ),
        migrations.AlterField(
            model_name='tc_sent_packet',
            name='send_datetime',
            field=models.DateTimeField(default=django.utils.timezone.now),
        ),
        migrations.AlterField(
            model_name='tc_template',
            name='modification_time',
            field=models.DateTimeField(default=django.utils.timezone.now),
        ),
    ]

0003_sent_tc_qm_validation

# -*- coding: utf-8 -*-
from __future__ import unicode_literals

from django.db import models, migrations
import django.utils.timezone


class Migration(migrations.Migration):

    dependencies = [
        ('Telecommands', '0002_auto_20161229_1325'),
    ]

    operations = [
        migrations.CreateModel(
            name='Sent_TC_QM_Validation',
            fields=[
                ('id', models.AutoField(verbose_name='ID', serialize=False, auto_created=True, primary_key=True)),
                ('TC_ID', models.IntegerField(null=True)),
                ('TC_List_Name', models.CharField(max_length=50, blank=True)),
                ('Telecommand_Name', models.CharField(max_length=50, blank=True)),
                ('Table_Name', models.CharField(max_length=50, blank=True)),
                ('Parameter', models.CharField(max_length=50, blank=True)),
                ('Expected_Value_Min', models.CommaSeparatedIntegerField(max_length=50, null=True)),
                ('Expected_Value_Max', models.CommaSeparatedIntegerField(max_length=50, null=True)),
                ('Time_Stamp', models.DateTimeField(verbose_name=django.utils.timezone.now)),
                ('Received_Value', models.CommaSeparatedIntegerField(max_length=50, null=True)),
                ('Success', models.NullBooleanField()),
                ('Comments', models.CharField(max_length=50, blank=True)),
            ],
        ),
    ]

Если у вас нет файла db.sqlite3, значит вы никогда не мигрировали свои модели в базу данных.

Сначала попробуйте выполнить python manage.py makemigrations для создания миграций, а затем выполнить python manage.py migrate для применения этих миграций.

Также замените вашу переменную DATABASES settings.py на следующую:

DATABASES = {
    'default': {
        'ENGINE': 'django.db.backends.sqlite3',
        'NAME': BASE_DIR / 'db.sqlite3',
    }
}
Вернуться на верх