Django OperationalError: missing table; migration does not recognize the missing table

I'm having problems with Django 1.7, I try to save the user in a table, but I get an error that the table does not exist.

Here is the code that I am executing:

from django.conf import settings
from django.contrib.auth import BACKEND_SESSION_KEY, SESSION_KEY, get_user_model
User = get_user_model()
from django.contrib.sessions.backends.db import SessionStore
from django.core.management.base import BaseCommand
class Command(BaseCommand):

    def handle(self, email, *_, **__):

        session_key = create_pre_authenticated_session(email)
        self.stdout.write(session_key)


def create_pre_authenticated_session(email):
    user = User.objects.create(email=email)
    session = SessionStore()
    session[SESSION_KEY] = user.pk
    session[BACKEND_SESSION_KEY] = settings.AUTHENTICATION_BACKENDS[0]
    session.save()
    return session.session_key

However, with

    user = User.objects.create(email=email)  

I get the error message :

 django.db.utils.OperationalError: no such table: accounts_user  

Here is the user model in the /models.py accounts that I am trying to use to build the table:

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

class User(models.Model):
    email = models.EmailField(primary_key=True)
    last_login = models.DateTimeField(default=timezone.now)
    REQUIRED_FIELDS = ()
    USERNAME_FIELD = 'email'

    def is_authenticated(self):
        return True

I ran sqlmigrate against this migration with , and I returned the correct SQL creation table, but the run gives me the following: 'manage.py accounts 0001.initial' 'manage.py migrate'

Operations to perform:
  Apply all migrations: sessions, admin, lists, contenttypes, accounts, auth
Running migrations:
  No migrations to apply. 

- "makemigration" , . , , , , Django , , , Django , , , .
Django , , , ?

+4
1

@user856358 sqlite . , , . settings.py:

DATABASES = {
    'default': {
        'ENGINE': 'django.db.backends.sqlite3',
        'NAME': os.path.join(BASE_DIR, '../database/db.sqlite3'),
    }
}

.sqlite3, ...

django.db.utils.OperationalError: no such table: accounts_user
$ rm ../database/db.sqlite3 
$ python3 manage.py migrate
+2

Source: https://habr.com/ru/post/1570261/


All Articles