R
R
Robin Alikhanov2020-01-14 23:40:57
Django
Robin Alikhanov, 2020-01-14 23:40:57

Error creating django super user?

from django.db import models  # Из модуля импортируем модели

"""
        Тут описывается, как должны выглядеть наши таблицы в базе данных
        ====================================================================
        Свойства, которое описано в классе будут столбцами в таблицах базы данных
        """


class Category(models.Model):
    """Модель категорий"""
    """из модуля находим класс и наследуемся от него"""
    """создаем свойство класса, который создаст столбец таблицы в БД для имени и url"""
    name = models.CharField(verbose_name="имя", max_length=140)
    slug = models.SlugField(verbose_name="url", max_length=100)

    def __str__(self):
        """Прописываем метод, чтобы в админ панели выводилось распечатку объекта"""
        return self.name

    class Meta:
        """Этот метод меняет название класса в админ части сайта"""
        verbose_name = 'Категория'
        """название класса в множественном числе"""
        verbose_name_plural = 'Категории'


class Tag(models.Model):
    """Модель Тэгов"""
    name = models.CharField(verbose_name="имя", max_length=140)
    slug = models.SlugField(verbose_name="url", max_length=100)

    def __str__(self):
        return self.name

    class Meta:
        verbose_name = 'Тег'
        verbose_name_plural = 'Теги'


class Post(models.Model):
    """Модель Постов"""
    title = models.CharField(verbose_name="Заглавие", max_length=500)
    mini_text = models.TextField(verbose_name="краткое содержание")
    text = models.TextField(verbose_name='полное содержание', max_length=10000000)
    created_date = models.DateField(verbose_name='дата создания', auto_now_add=True)
    slug = models.SlugField(verbose_name='url', max_length=100, unique=True)
    category = models.ForeignKey(Category, verbose_name='категория', on_delete=models.CASCADE, null=True)
    tags = models.ManyToManyField(Tag, verbose_name='тэг', blank=True)

    def __str__(self):
        return self

    class Meta:
        verbose_name = 'Пост'
        verbose_name_plural = 'Посты'


class Comment(models.Model):
    """Модель комментариев"""
    post = models.ForeignKey(Post, verbose_name='статья', on_delete=models.CASCADE)
    text = models.TextField(verbose_name='текст комментария')
    created_date = models.DateField('дата создания')
    moderation = models.BooleanField(default=True)

    def __str__(self):
        return self.text

    class Meta:
        verbose_name = 'Комментарий'
        verbose_name_plural = 'Комментарии'

1. python manage.py migrate # Create first base tables with session , user and other nonsense
2. python manage.py makemigrations # enable migrations to enable migrations in blog app where above code is in model.py file
3. python manage. py migrate # running migrations
=================== Everything works like clockwork until this point
4. python manage.py createsuperuser # trying to create a super user to login to the admin panel
accepts all the data and at the end gives such an error, I can’t understand what’s wrong.
What is strange is doing the opposite, that is, at the beginning of creating a super user, it was created, but already migrations in the model caused a similar situation.
I can not understand why the super user conflicts with application migrations. I've been sitting on the Internet for three hours and I can't find something sensible
Username (leave blank to use 'rihard'): admin
E-mail address: [email protected]
Password:
Password (again):
Traceback (most recent call last) :
File "C:\shop\pvm\lib\site-packages\django\db\backends\utils.py", line 84, in _execute
return self.cursor.execute(sql, params)
File "C:\shop\ pvm\lib\site-packages\django\db\backends\sqlite3\base.py", line 383, in execute
return Database.Cursor.execute(self, query, params)
sqlite3.OperationalError:
Traceback (most recent call last):
File "manage.py", line 21, in
main()
File "manage.py", line 17, in main
execute_from_command_line(sys.argv)
File "C:\shop\pvm\lib \site-packages\django\core\management\__init__.py", line 381, in execute_from_command_line
utility.execute()
File "C:\shop\pvm\lib\site-packages\django\core\management\__init__.py ", line 375, in execute
self.fetch_command(subcommand).run_from_argv(self.argv)
File "C:\shop\pvm\lib\site-packages\django\core\management\base.py", line 323, in run_from_argv
self.execute(*args, **cmd_options)
File "C:\shop\pvm\lib\site-packages\django\contrib\auth\management\commands\createsuperuser.py", line 61, in execute
return super().execute(*args, **options)
File "C:\shop\pvm\lib\site-packages\django\core\management\base.py", line 364, in execute
output = self.handle (*args, **options)
File "C:\shop\pvm\lib\site-packages\django\contrib\auth\management\commands\createsuperuser.py", line 156, in handle
self.UserModel._default_manager.db_manager (database).create_superuser(**user_data)
File "C:\shop\pvm\lib\site-packages\django\contrib\auth\models.py", line 162, in create_superuser
return self._create_user(username, email, password, **extra_fields)
File "C:\shop\pvm\lib\site-packages\django\contrib\auth\models.py", line 145, in _create_user
user.save(using=self._db)
File "C:\shop\pvm\lib\site-packages\django\contrib\auth\base_user.py", line 66, in save
super().save(*args, **kwargs)
File "C:\shop \pvm\lib\site-packages\django\db\models\base.py", line 740, in save
self.save_base(using=using, force_insert=force_insert,
File "C:\shop\pvm\lib\site- packages\django\db\models\base.py", line 777, in save_base
updated = self._save_table(
File "C:\shop\pvm\lib\site-packages\django\db\models\base.py", line 870, in _save_table
result = self._do_insert(cls._base_manager, using, fields, update_pk, raw)
File "C:\shop\pvm\lib\site-packages\django\db\models\base.py", line 907, in _do_insert
return manager._insert([self], fields=fields,return_id=update_pk,
File "C:\shop\pvm\lib\site-packages\django\db\models\manager.py", line 82, in manager_method
return getattr(self.get_queryset(), name)(*args, **kwargs)
File "C:\shop\pvm\lib\site-packages\django\db\models\query.py", line 1186, in _insert
return query.get_compiler(using=using).execute_sql(return_id)
File "C:\ shop\pvm\lib\site-packages\django\db\models\sql\compiler.py", line 1368, in execute_sql
cursor.execute(sql, params)
File "C:\shop\pvm\lib\site-packages \django\db\backends\utils.py", line 99, in execute
return super().execute(sql, params)
File "C:\shop\pvm\lib\site-packages\django\db\backends\utils .py", line 67, in execute
return self._execute_with_wrappers(sql, params, many=False, executor=self._execute)
File "C:\shop\pvm\lib\site-packages\django\db\backends\utils.py", line 76, in _execute_with_wrappers
return executor(sql, params, many, context)
File "C:\shop\pvm\lib\site-packages\django\db\backends\utils.py", line 84, in _execute
return self.cursor.execute(sql , params)
File "C:\shop\pvm\lib\site-packages\django\db\utils.py", line 89, in __exit__
raise dj_exc_value.with_traceback(traceback) from exc_value
File "C:\shop\pvm\ lib\site-packages\django\db\backends\utils.py", line 84, in _execute
return self.cursor.execute(sql, params)
File "C:\shop\pvm\lib\site-packages\django\db\backends\sqlite3\base.py", line 383, in execute
return Database.Cursor.execute(self, query, params)
django.db. utils.OperationalError: database is locked

Answer the question

In order to leave comments, you need to log in

1 answer(s)
V
Vladislava, 2021-12-28
@vladis005

By default, multiple processes can open the same SQLite database at the same time, and multiple read requests can run in parallel.
In the write case, a single write to the database locks the database for a short time, nothing, not even a read, can access the database file at all.
https://stackoverflow.com/questions/10325683/can-i ...
Change database to MySQL or PostgreSQL - these locks are not there

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question