Makemigrations are not executed and tables are not created in the Django database

Development in Visual Studio 2017. When performing "makemigrations", as well as when checking "manage.py check" I have the same system response:


Execution is underway: manage.py makemigrations

Traceback (most recent call last):
File "...\DjangoWeb\env\lib\site-packages\django\db\backends\utils.py", line 64, in execute
    return self.cursor.execute(sql, params)

File "...\DjangoWeb\env\lib\site-packages\django\db\backends\sqlite3\base.py", line 328, in execute

return Database.Cursor.execute(self, query, params)
sqlite3.OperationalError: no such table: app_entry

The above exception was the direct cause of the following exception:

Traceback (most recent call last):
File "...\DjangoWeb\manage.py", line 17, in <module>

execute_from_command_line(sys.argv)

File "...\DjangoWeb\env\lib\site-packages\django\core\management\__init__.py", line 364, in execute_from_command_line
    utility.execute()

File "...\DjangoWeb\env\lib\site-packages\django\core\management\__init__.py", line 356, in execute
    self.fetch_command(subcommand).run_from_argv(self.argv)

File "...\DjangoWeb\env\lib\site-packages\django\core\management\base.py", line 283, in run_from_argv
    self.execute(*args, **cmd_options)

File "...\DjangoWeb\env\lib\site-packages\django\core\management\base.py", line 327, in execute
    self.check()

File "...\DjangoWeb\env\lib\site-packages\django\core\management\base.py", line 359, in check
    include_deployment_checks=include_deployment_checks,

File "...\DjangoWeb\env\lib\site-packages\django\core\management\base.py", line 346, in _run_checks
    return checks.run_checks(**kwargs)

File "...\DjangoWeb\env\lib\site-packages\django\core\checks\registry.py", line 81, in run_checks
    new_errors = check(app_configs=app_configs)

File "...\DjangoWeb\env\lib\site-packages\django\core\checks\urls.py", line 16, in check_url_config
    return check_resolver(resolver)

File "...\DjangoWeb\env\lib\site-packages\django\core\checks\urls.py", line 26, in check_resolver
    return check_method()

File "...\DjangoWeb\env\lib\site-packages\django\urls\resolvers.py", line 256, in check
    for pattern in self.url_patterns:

File "...\DjangoWeb\env\lib\site-packages\django\utils\functional.py", line 35, in __get__
    res = instance.__dict__[self.name] = self.func(instance)

File "...\DjangoWeb\env\lib\site-packages\django\urls\resolvers.py", line 407, in url_patterns
    patterns = getattr(self.urlconf_module, "urlpatterns", self.urlconf_module)

File "...\DjangoWeb\env\lib\site-packages\django\utils\functional.py", line 35, in __get__
    res = instance.__dict__[self.name] = self.func(instance)

File "...\DjangoWeb\env\lib\site-packages\django\urls\resolvers.py", line 400, in urlconf_module
    return import_module(self.urlconf_name)

File "...\Microsoft Visual Studio\Shared\Python36_64\lib\importlib\__init__.py", line 126, in import_module
    return _bootstrap._gcd_import(name[level:], package, level)

File "<frozen importlib._bootstrap>", line 994, in _gcd_import
  File "<frozen importlib._bootstrap>", line 971, in _find_and_load
  File "<frozen importlib._bootstrap>", line 955, in _find_and_load_unlocked
  File "<frozen importlib._bootstrap>", line 665, in _load_unlocked
  File "<frozen importlib._bootstrap_external>", line 678, in exec_module
  File "<frozen importlib._bootstrap>", line 219, in _call_with_frames_removed
  File ".\DjangoWeb\urls.py", line 8, in <module>
    import app.views

File ".\app\views.py", line 68, in <module>
    ENTRY_COUNT = Entry.objects.count() # кол-во зявок в БД

File "...\DjangoWeb\env\lib\site-packages\django\db\models\manager.py", line 85, in manager_method
    return getattr(self.get_queryset(), name)(*args, **kwargs)

File "...\DjangoWeb\env\lib\site-packages\django\db\models\query.py", line 364, in count
    return self.query.get_count(using=self.db)

File "...\DjangoWeb\env\lib\site-packages\django\db\models\sql\query.py", line 499, in get_count
    number = obj.get_aggregation(using, ['__count'])['__count']

File "...\DjangoWeb\env\lib\site-packages\django\db\models\sql\query.py", line 480, in get_aggregation
    result = compiler.execute_sql(SINGLE)

File "...\DjangoWeb\env\lib\site-packages\django\db\models\sql\compiler.py", line 899, in execute_sql
    raise original_exception

File "...\DjangoWeb\env\lib\site-packages\django\db\models\sql\compiler.py", line 889, in execute_sql
    cursor.execute(sql, params)

File "...\DjangoWeb\env\lib\site-packages\django\db\backends\utils.py", line 79, in execute
    return super(CursorDebugWrapper, self).execute(sql, params)

File "...\DjangoWeb\env\lib\site-packages\django\db\backends\utils.py", line 64, in execute
    return self.cursor.execute(sql, params)

File "...\DjangoWeb\env\lib\site-packages\django\db\utils.py", line 94, in __exit__
    six.reraise(dj_exc_type, dj_exc_value, traceback)

File ...\DjangoWeb\env\lib\site-packages\django\utils\six.py", line 685, in reraise
    raise value.with_traceback(tb)

File "...\DjangoWeb\env\lib\site-packages\django\db\backends\utils.py", line 64, in execute
    return self.cursor.execute(sql, params)

File "...\DjangoWeb\env\lib\site-packages\django\db\backends\sqlite3\base.py", line 328, in execute
    return Database.Cursor.execute(self, query, params)
django.db.utils.OperationalError: no such table: app_entry

In this case, all migration files in the "migration" project folder are deleted, except for the "-- "file. init--.py", and deleted the file of the database itself and re-created by the system, but constantly gives the above error..

What could be the problem here and how is it fix it?

Author: JBlack, 2019-03-03

1 answers

To add the required table to your existing database(for me it was account_profile), you need to first download "DB Browser for SQLite" and do the following:

  1. Copy the existing 'db.sqlite3' to a folder.
  2. Delete it from the project folder.
  3. Run " python3 manage.py make migrations’", then "python3 manage.py migrate".
  4. Open your new database in "DB Browser for SQLite".
  5. Then you need to export the 'account_profile' table as a CSV file. Shown in image1(below the comment)
  6. Then delete your new DB and throw back the old one
  7. Now open your old DB in "DB Browser for SQLite", click "File" - > "Import" -> "Table as CSV file" and select your CSV file(it just contains the necessary table)
  8. Then you will see that the columns in the table are named as 'field1' and 'field2’, change them to’ id ’and’ user_id' respectively. Shown on image2 and image3
  9. Then you can either delete the admin in the database, or see what his id is and enter it(for example, the admin id is 5, write in the column 'id’ -' 1’, in the column ‘user_id’ - ' 5’)

If you have any problems, write, I will be happy to answer)

image1

image2

image3

Result)

 2
Author: Block2busted, 2020-04-08 13:25:07