Q: Sqllite and Django shell are not in sync I have deleted a table from sqllite3 shell and then when I try creating it again by running python manage.py migrate/python manage.py makemigrations table is not created and showing below error. How to re-create the table and make my db and the API is insync. I tried with the python manage.py dbsync also but not worked.
Operations to perform:
  Apply all migrations: admin, auth, cgkapp, contenttypes, sessions
Running migrations:
  Applying cgkapp.0002_delete_questions...Traceback (most recent call last):
  File "/home/shrivatsa555/.virtualenvs/django20/lib/python3.6/site-packages/django/db/backends/utils.py", line 85, in _execute
    return self.cursor.execute(sql, params)
  File "/home/shrivatsa555/.virtualenvs/django20/lib/python3.6/site-packages/django/db/backends/sqlite3/base.py", line 303, in execute
    return Database.Cursor.execute(self, query, params)
sqlite3.OperationalError: no such table: cgkapp_questions

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/shrivatsa555/.virtualenvs/django20/lib/python3.6/site-packages/django/core/management/__init__.py", line 371, in execute_from_command_line
    utility.execute()
  File "/home/shrivatsa555/.virtualenvs/django20/lib/python3.6/site-packages/django/core/management/__init__.py", line 365, in execute
    self.fetch_command(subcommand).run_from_argv(self.argv)
  File "/home/shrivatsa555/.virtualenvs/django20/lib/python3.6/site-packages/django/core/management/base.py", line 288, in run_from_argv
    self.execute(*args, **cmd_options)
  File "/home/shrivatsa555/.virtualenvs/django20/lib/python3.6/site-packages/django/core/management/base.py", line 335, in execute
    output = self.handle(*args, **options)
  File "/home/shrivatsa555/.virtualenvs/django20/lib/python3.6/site-packages/django/core/management/commands/migrate.py", line 200, in handle
    fake_initial=fake_initial,
  File "/home/shrivatsa555/.virtualenvs/django20/lib/python3.6/site-packages/django/db/migrations/executor.py", line 117, in migrate
    state = self._migrate_all_forwards(state, plan, full_plan, fake=fake, fake_initial=fake_initial)
  File "/home/shrivatsa555/.virtualenvs/django20/lib/python3.6/site-packages/django/db/migrations/executor.py", line 147, in _migrate_all_forwards
    state = self.apply_migration(state, migration, fake=fake, fake_initial=fake_initial)
  File "/home/shrivatsa555/.virtualenvs/django20/lib/python3.6/site-packages/django/db/migrations/executor.py", line 244, in apply_migration
    state = migration.apply(state, schema_editor)
  File "/home/shrivatsa555/.virtualenvs/django20/lib/python3.6/site-packages/django/db/migrations/migration.py", line 122, in apply
    operation.database_forwards(self.app_label, schema_editor, old_state, project_state)
  File "/home/shrivatsa555/.virtualenvs/django20/lib/python3.6/site-packages/django/db/migrations/operations/models.py", line 246, in database_forwa
rds
    schema_editor.delete_model(model)
  File "/home/shrivatsa555/.virtualenvs/django20/lib/python3.6/site-packages/django/db/backends/sqlite3/schema.py", line 287, in delete_model
    super().delete_model(model)
  File "/home/shrivatsa555/.virtualenvs/django20/lib/python3.6/site-packages/django/db/backends/base/schema.py", line 317, in delete_model
    "table": self.quote_name(model._meta.db_table),
  File "/home/shrivatsa555/.virtualenvs/django20/lib/python3.6/site-packages/django/db/backends/base/schema.py", line 117, in execute
    cursor.execute(sql, params)
  File "/home/shrivatsa555/.virtualenvs/django20/lib/python3.6/site-packages/django/db/backends/utils.py", line 100, in execute
    return super().execute(sql, params)
  File "/home/shrivatsa555/.virtualenvs/django20/lib/python3.6/site-packages/django/db/backends/utils.py", line 68, in execute
    return self._execute_with_wrappers(sql, params, many=False, executor=self._execute)
  File "/home/shrivatsa555/.virtualenvs/django20/lib/python3.6/site-packages/django/db/backends/utils.py", line 77, in _execute_with_wrappers
    return executor(sql, params, many, context)
  File "/home/shrivatsa555/.virtualenvs/django20/lib/python3.6/site-packages/django/db/backends/utils.py", line 85, in _execute
    return self.cursor.execute(sql, params)
  File "/home/shrivatsa555/.virtualenvs/django20/lib/python3.6/site-packages/django/db/utils.py", line 89, in __exit__
    raise dj_exc_value.with_traceback(traceback) from exc_value
  File "/home/shrivatsa555/.virtualenvs/django20/lib/python3.6/site-packages/django/db/backends/utils.py", line 85, in _execute
    return self.cursor.execute(sql, params)
  File "/home/shrivatsa555/.virtualenvs/django20/lib/python3.6/site-packages/django/db/backends/sqlite3/base.py", line 303, in execute
    return Database.Cursor.execute(self, query, params)
django.db.utils.OperationalError: no such table: cgkapp_questions


A: Django migrate command try to make all migrations (they hold in migrations directory) which are not done yet. 
In here you have "0002_delete_questions" migration file in your migrations directory and when you run the migrate command this migration try to delete questions table from your database but this table is already deleted. So you can handle this in two way


*

*Delete this migration file from migrations directory in your project

*run this command python manage.py migrate --fake cgkapp 0002_delete_questions (here 'cgkapp' is your app name and '0002_delete_questions' is your migration file name)

