django-cms / django-filer

File and Image Management Application for django
https://django-filer.readthedocs.io/
Other
1.73k stars 575 forks source link

CircularDependencyError( django.db.migrations.exceptions.CircularDependencyError: accounts.0001_initial, filer.0001_initial #1296

Closed Prashant4900 closed 2 years ago

Prashant4900 commented 2 years ago

How can I fix that?

Setting.py

INSTALLED_APPS = [
    ...
    # Media Library
    'easy_thumbnails',
    'filer',
    'mptt',
]

THUMBNAIL_PROCESSORS = [
    'easy_thumbnails.processors.colorspace',
    'easy_thumbnails.processors.autocrop',
    'easy_thumbnails.processors.scale_and_crop',
    'filer.thumbnail_processors.scale_and_crop_with_subject_location',
    'easy_thumbnails.processors.filters',
]

FILER_CANONICAL_URL = 'sharing/'

Urls.py

path('filer/', include('filer.urls')),
path('', include('filer.server.urls')),

Model.py

from filer.fields.image import FilerImageField

class CustomUser(AbstractUser):
    photo = FilerImageField(null=True, blank=True, on_delete=models.CASCADE)

Exceptions

(env) F:\work\mason\django\simple-django-rest-starter>python manage.py makemigrations
Migrations for 'accounts':
  accounts\migrations\0001_initial.py
    - Create model CustomUser

(env) F:\work\mason\django\simple-django-rest-starter>python manage.py migrate
Traceback (most recent call last):
  File "manage.py", line 22, in <module>
    main()
  File "manage.py", line 18, in main
    execute_from_command_line(sys.argv)
  File "F:\work\mason\django\simple-django-rest-starter\env\lib\site-packages\django\core\management\__init__.py", line 446, in execute_from_command_line
    utility.execute()
  File "F:\work\mason\django\simple-django-rest-starter\env\lib\site-packages\django\core\management\__init__.py", line 440, in execute
    self.fetch_command(subcommand).run_from_argv(self.argv)
  File "F:\work\mason\django\simple-django-rest-starter\env\lib\site-packages\django\core\management\base.py", line 414, in run_from_argv
    self.execute(*args, **cmd_options)
  File "F:\work\mason\django\simple-django-rest-starter\env\lib\site-packages\django\core\management\base.py", line 460, in execute
    output = self.handle(*args, **options)
  File "F:\work\mason\django\simple-django-rest-starter\env\lib\site-packages\django\core\management\base.py", line 98, in wrapped
    res = handle_func(*args, **kwargs)
  File "F:\work\mason\django\simple-django-rest-starter\env\lib\site-packages\django\core\management\commands\migrate.py", line 108, in handle
    executor = MigrationExecutor(connection, self.migration_progress_callback)
  File "F:\work\mason\django\simple-django-rest-starter\env\lib\site-packages\django\db\migrations\executor.py", line 18, in __init__
    self.loader = MigrationLoader(self.connection)
  File "F:\work\mason\django\simple-django-rest-starter\env\lib\site-packages\django\db\migrations\loader.py", line 58, in __init__
    self.build_graph()
  File "F:\work\mason\django\simple-django-rest-starter\env\lib\site-packages\django\db\migrations\loader.py", line 305, in build_graph
    self.graph.ensure_not_cyclic()
  File "F:\work\mason\django\simple-django-rest-starter\env\lib\site-packages\django\db\migrations\graph.py", line 284, in ensure_not_cyclic
    raise CircularDependencyError(
django.db.migrations.exceptions.CircularDependencyError: accounts.0001_initial, filer.0001_initial
marksweb commented 2 years ago

Hi @Prashant4900

This appears to be a problem in migration files.

Can you include that initial migration from your accounts app? It must be causing the issue with filer

Prashant4900 commented 2 years ago

@marksweb Here is the migration file

000_initial.py File

# Generated by Django 4.0.5 on 2022-06-11 13:23

from django.conf import settings
from django.db import migrations, models
import django.db.models.deletion
import django.utils.timezone
import filer.fields.image

class Migration(migrations.Migration):

    initial = True

    dependencies = [
        migrations.swappable_dependency(settings.FILER_IMAGE_MODEL),
        ('auth', '0012_alter_user_first_name_max_length'),
    ]

    operations = [
        migrations.CreateModel(
            name='CustomUser',
            fields=[
                ('id', models.BigAutoField(auto_created=True, primary_key=True, serialize=False, verbose_name='ID')),
                ('password', models.CharField(max_length=128, verbose_name='password')),
                ('last_login', models.DateTimeField(blank=True, null=True, verbose_name='last login')),
                ('is_superuser', models.BooleanField(default=False, help_text='Designates that this user has all permissions without explicitly assigning them.', verbose_name='superuser status')),
                ('first_name', models.CharField(blank=True, max_length=150, verbose_name='first name')),
                ('last_name', models.CharField(blank=True, max_length=150, verbose_name='last name')),
                ('is_staff', models.BooleanField(default=False, help_text='Designates whether the user can log into this admin site.', verbose_name='staff status')),
                ('is_active', models.BooleanField(default=True, help_text='Designates whether this user should be treated as active. Unselect this instead of deleting accounts.', verbose_name='active')),
                ('date_joined', models.DateTimeField(default=django.utils.timezone.now, verbose_name='date joined')),
                ('username', models.CharField(blank=True, max_length=25, null=True, unique=True)),
                ('email', models.EmailField(max_length=254, unique=True, verbose_name='email address')),
                ('date_of_birth', models.DateField(blank=True, null=True)),
                ('phone', models.CharField(blank=True, max_length=15, null=True)),
                ('groups', models.ManyToManyField(blank=True, help_text='The groups this user belongs to. A user will get all permissions granted to each of their groups.', related_name='user_set', related_query_name='user', to='auth.group', verbose_name='groups')),
                ('photo', filer.fields.image.FilerImageField(blank=True, null=True, on_delete=django.db.models.deletion.CASCADE, to=settings.FILER_IMAGE_MODEL)),
                ('user_permissions', models.ManyToManyField(blank=True, help_text='Specific permissions for this user.', related_name='user_set', related_query_name='user', to='auth.permission', verbose_name='user permissions')),
            ],
            options={
                'verbose_name': 'User',
                'verbose_name_plural': 'Users',
            },
        ),
    ]
marksweb commented 2 years ago

@Prashant4900 ok, so filer's initial migration depends on the auth initial migration. So your accouts app wants filer to install first and filer wants your accounts app to install first.

To resolve, don't include the filer field on your model until after the first migration. So take the filer field out of the model, create the migration, then add the field back in and create another migration.

Prashant4900 commented 2 years ago

@Prashant4900 ok, so filer's initial migration depends on the auth initial migration. So your accouts app wants filer to install first and filer wants your accounts app to install first.

To resolve, don't include the filer field on your model until after the first migration. So take the filer field out of the model, create the migration, then add the field back in and create another migration.

Thanks it's worked