4

I'm trying to set a custom AUTH_USER_MODEL in my settings but it throws me a CircularDependencyError due to some past migrations. (I used the regular User before)

How can I fix this? I don't care about the database it's just a single test object. But can I reset/remove the migrations or do I need to start a whole new project?

user3199840
  • 525
  • 2
  • 13
  • 35

3 Answers3

3

Django warns against changing AUTH_USER_MODEL in the docs:

Changing AUTH_USER_MODEL has a big effect on your database structure. It changes the tables that are available, and it will affect the construction of foreign keys and many-to-many relationships. If you intend to set AUTH_USER_MODEL, you should set it before creating any migrations or running manage.py migrate for the first time.

Changing this setting after you have tables created is not supported by makemigrations and will result in you having to manually fix your schema, port your data from the old user table, and possibly manually reapply some migrations.

If you don't care about the database, then I would try dropping the database, deleting your existing migrations files and running makemigrations again.

Community
  • 1
  • 1
Alasdair
  • 298,606
  • 55
  • 578
  • 516
  • Thanks! Can I just delete the folder or do I need to do anything else. (I remember having some troubles when deleting migrations like this before) – user3199840 Jun 07 '16 at 12:31
  • 2
    I would delete all of the files in the `migrations` folder except the `__init__.py`. If you delete the entire migrations folder, I believe you'll have to run `./mange.py makemigrations ` to create the initial migration for that app. – Alasdair Jun 07 '16 at 12:39
0

You can easily remove migrations by simply deleting the migration files and entries in your database. Then you can migrate again to create your 'first' migration.

Alex
  • 42
  • 6
  • Thank you. Are you sure of this? How do I remove it? Just deleting or emptying the folder at each app level? I remember having some problems with removing migrations like this before. I'm using 1.8 – user3199840 Jun 07 '16 at 12:25
  • 1
    Simply delete the files (apart from the __init__.py) in the migrations folders. Then delete the entries in the migrations table of your database. It is quite safe to do, especially if this is a test project. All you are doing is deleting Django's history of your migrations. The models are unchanged and a fresh history is created when you next run `makemigrations` – Alex Jun 07 '16 at 12:33
0

As I stated here, just delete the migrations folder and the db.sqlite3 file in your file-browser (or whatever you chose as your database-language, there will be a database-file in your project directory then).

Only do this if you are sure that you can live with losing the whole database completely and that you will need to start over again with all the migrations and with the data-input as well.

ElectRocnic
  • 1,275
  • 1
  • 14
  • 25