0

I've ran all the commands under the sun to try and fix this which normally solve the problem but this time nothing is working.

python manage.py makemigrations
python manage.py migrate
python manage.py migrate --run-syncdb
python manage.py migrate --fake users 
python manage.py migrate users 0012

I've read a few questions on SO and now think it has to do with something executing immediately when imported so the migration doesn't go through.

The only thing I've changed is added a new model TextSubmission and altered views.py. If someone could show me / identify the problematic code, I would greatly appreciate it.

Running migrations:
  Rendering model states... DONE
  Unapplying users.0014_auto_20190314_1141...Traceback (most recent call last):
  File "/home/user/env/lib/python3.6/site-packages/django/db/backends/utils.py", line 85, in _execute
    return self.cursor.execute(sql, params)
  File "/home/user/env/lib/python3.6/site-packages/django/db/backends/sqlite3/base.py", line 298, in execute
    return Database.Cursor.execute(self, query, params)
sqlite3.OperationalError: no such table: users_textsubmission

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

Traceback (most recent call last):
  File "manage.py", line 15, in <module>
    execute_from_command_line(sys.argv)
  File "/home/user/env/lib/python3.6/site-packages/django/core/management/__init__.py", line 381, in execute_from_command_line
    utility.execute()
  File "/home/user/env/lib/python3.6/site-packages/django/core/management/__init__.py", line 375, in execute
    self.fetch_command(subcommand).run_from_argv(self.argv)
  File "/home/user/env/lib/python3.6/site-packages/django/core/management/base.py", line 316, in run_from_argv
    self.execute(*args, **cmd_options)
  File "/home/user/env/lib/python3.6/site-packages/django/core/management/base.py", line 353, in execute
    output = self.handle(*args, **options)
  File "/home/user/env/lib/python3.6/site-packages/django/core/management/base.py", line 83, in wrapped
    res = handle_func(*args, **kwargs)
  File "/home/user/env/lib/python3.6/site-packages/django/core/management/commands/migrate.py", line 203, in handle
    fake_initial=fake_initial,
  File "/home/user/env/lib/python3.6/site-packages/django/db/migrations/executor.py", line 121, in migrate
    state = self._migrate_all_backwards(plan, full_plan, fake=fake)
  File "/home/user/env/lib/python3.6/site-packages/django/db/migrations/executor.py", line 196, in _migrate_all_backwards
    self.unapply_migration(states[migration], migration, fake=fake)
  File "/home/user/env/lib/python3.6/site-packages/django/db/migrations/executor.py", line 262, in unapply_migration
    state = migration.unapply(state, schema_editor)
  File "/home/user/env/lib/python3.6/site-packages/django/db/migrations/migration.py", line 175, in unapply
    operation.database_backwards(self.app_label, schema_editor, from_state, to_state)
  File "/home/user/env/lib/python3.6/site-packages/django/db/migrations/operations/models.py", line 96, in database_backwards
    schema_editor.delete_model(model)
  File "/home/user/env/lib/python3.6/site-packages/django/db/backends/sqlite3/schema.py", line 290, in delete_model
    super().delete_model(model)
  File "/home/user/env/lib/python3.6/site-packages/django/db/backends/base/schema.py", line 331, in delete_model
    "table": self.quote_name(model._meta.db_table),
  File "/home/user/env/lib/python3.6/site-packages/django/db/backends/base/schema.py", line 133, in execute
    cursor.execute(sql, params)
  File "/home/user/env/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/user/env/lib/python3.6/site-packages/django/db/backends/utils.py", line 77, in _execute_with_wrappers
    return executor(sql, params, many, context)
  File "/home/user/env/lib/python3.6/site-packages/django/db/backends/utils.py", line 85, in _execute
    return self.cursor.execute(sql, params)
  File "/home/user/env/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/user/env/lib/python3.6/site-packages/django/db/backends/utils.py", line 85, in _execute
    return self.cursor.execute(sql, params)
  File "/home/user/env/lib/python3.6/site-packages/django/db/backends/sqlite3/base.py", line 298, in execute
    return Database.Cursor.execute(self, query, params)
django.db.utils.OperationalError: no such table: users_textsubmission

models.py

class TextSubmission(models.Model):
    text_submission    = models.CharField(max_length=50, null=True, blank=True)
    user                   = models.OneToOneField(User, on_delete=models.CASCADE)

    class Meta:
        ordering = ['text_submission']

    def __str__(self):
        return self.text_submission

views.py

def profile_view(request):
    if request.method == 'POST':
        p_form = ProfileUpdateForm(request.POST, instance=request.user)
        try:
           t_form = TextSubmissionForm(request.POST, instance=request.user.textsubmission)
        except TextSubmission.DoesNotExist:
           t_form = TextSubmissionForm(request.POST)

        if p_form.is_valid() and t_form.is_valid():
            p_form.save()
            t_form.save()
            messages.success(request, f'Your account has been updated!')
            return redirect('profile')

    else:
        p_form = ProfileUpdateForm(instance=request.user.profile)
        t_form = TextSubmissionForm(instance=request.user.profile)

    context = {
        'p_form': p_form,
        't_form': t_form,
    }

    return render(request, 'profile.html', context)
Trilla
  • 943
  • 2
  • 15
  • 31

0 Answers0