django-migrations

Extending a base model in django

Extending a base model in django Question: I want to create base model for my questions named Question and extend it by any other question types: class Question(models.Model): questionnaire = models.ForeignKey(to=’Questionnaire’, on_delete=models.CASCADE, related_name=’questions’) question = models.TextField() description = models.TextField(null=True, blank=True) media = models.FileField(upload_to=’medias’, blank=True, null=True) is_required = models.BooleanField(default=False) def __str__(self): return f'{self.questionnaire.name} – {self.question}’ and …

Total answers: 1

Django and pgAdmin not aligned

Django and pgAdmin not aligned Question: I was trying to change the order of the table columns in a postgreSQL table. As I am just starting, it seemed easier to manage.py flush and create a new DB with new name and apply migrations. I can see the new DB in pgAdmin received all the Django …

Total answers: 2

Custom django data migration creating records allauth.account EmailAddress model returns error – django.db.migrations.exceptions.NodeNotFoundError:

Custom django data migration creating records allauth.account EmailAddress model returns error – django.db.migrations.exceptions.NodeNotFoundError: Question: I am upgrading a django project that was created with the default django auth. Email verification was implemented with the django.contrib.auth.tokens package. The way it worked was that the ‘is_active’ flag of the default django user which itself is extended with …

Total answers: 2

How to erase/delete/wipe the migration history in Django

How to erase/delete/wipe the migration history in Django Question: I’m experimenting with varios django modells and settings. I can’t erase the migration history which is make me upset. I have run this script and physically delete all .pyc files and the database. del /s /q *.pyc del /q db.sqlite3 After I typed: python manage.py makemigrations …

Total answers: 2

Django test to check for pending migrations

Django test to check for pending migrations Question: Django has a –check argument that let’s you check if migrations need to be created for your project. This is relatively easy to add in CI, but that won’t perform the check on developer computers. I want to add this check as a unit test in my …

Total answers: 1

Django: Create a superuser in a data migration

Django: Create a superuser in a data migration Question: Goal: automatically creating a superuser I’m trying to create a default user, specifically a superuser, in an early data migration, so whenever my Django application is run in my Docker container, it already has a superuser with which I can access the admin site. I had …

Total answers: 3

Can't get proper response from `issubclass()` when called with Django's `__fake__` model type inside migration

Can't get proper response from `issubclass()` when called with Django's `__fake__` model type inside migration Question: I’m trying to generate UUIDs for some models in a migration. The problem is that the models returned from apps.get_app_config(app_name).get_models() are these __fake__ objects, they are what Django calls historical models, so calling issubclass(fake_model, UUIDModelMixin) returns False when I …

Total answers: 2

How to run migrations on specific database using call_command() in Django?

How to run migrations on specific database using call_command() in Django? Question: I’m just wondering what the correct syntax is for calling $ python manage.py migrate app_name –database db_name with the management.call_command() function at runtime. So far, I have the following: from django.core import management from django.core.management.commands import migrate # Migrate the core.contrib.dynamics if needed …

Total answers: 1

ValueError: Dependency on app with no migrations: customuser

ValueError: Dependency on app with no migrations: customuser Question: I am trying to start a webpage using the Django framework. This is my first web development project. After creating the project, I tried to start an app that utilizes customized users and registration with email validation using django-registration. This is what happened when I ran …

Total answers: 4

django.db.utils.OperationalError: 1005, 'Can't create table `xyz`.`#sql-600_237` (errno: 150 "Foreign key constraint is incorrectly formed")

django.db.utils.OperationalError: 1005, 'Can't create table `xyz`.`#sql-600_237` (errno: 150 "Foreign key constraint is incorrectly formed") Question: I am trying to add One-to-One keys into my Django app, but I always get that error when I try to “migrate” process (makemigrations works great). Applying xyzapp.0007_personne_extended_foreign…Traceback (most recent call last): File “manage.py”, line 29, in <module> execute_from_command_line(sys.argv) File …

Total answers: 4