Errors when I try to migrate in Django2











up vote
1
down vote

favorite
1












I have a problem (at least I think). I am new in all this, so I apologize If I ask something stupid.
I have some site, which is working normally. When I try to make migrations ( python manage.py makemigrations), everything passed ok, I got the message of how many models new I have, etc. But, when I run after that migrate, I got the following output:



Operations to perform:
Apply all migrations: admin, auth, comments, contenttypes, news, sessions
Running migrations:
Applying comments.0003_auto_20180816_2158...Traceback (most recent call last):
File "../venv/lib/python3.6/site-packages/django/db/backends/utils.py", line 85, in _execute
return self.cursor.execute(sql, params)
psycopg2.ProgrammingError: syntax error at or near "WITH ORDINALITY"
LINE 6: FROM unnest(c.conkey) WITH ORDINALITY co...
^


The above exception was the direct cause of the following exception:

Traceback (most recent call last):
File "manage.py", line 15, in <module>
execute_from_command_line(sys.argv)
File ".../venv/lib/python3.6/site-packages/django/core/management/__init__.py", line 381, in execute_from_command_line
utility.execute()
File ".../venv/lib/python3.6/site-packages/django/core/management/__init__.py", line 375, in execute
self.fetch_command(subcommand).run_from_argv(self.argv)
File ".../venv/lib/python3.6/site-packages/django/core/management/base.py", line 316, in run_from_argv
self.execute(*args, **cmd_options)
File
".../venv/lib/python3.6/site-packages/django/core/management/base.py", line 353, in execute
output = self.handle(*args, **options)
File
".../venv/lib/python3.6/site-packages/django/core/management/base.py", line 83, in wrapped
res = handle_func(*args, **kwargs)
File ".../venv/lib/python3.6/site-
packages/django/core/management/commands/migrate.py", line 203, in handle
fake_initial=fake_initial,
File


".../venv/lib/python3.6/site-
packages/django/db/backends/base/schema.py", line 531, in _alter_field
fk_names = self._constraint_names(model, [old_field.column],
foreign_key=True)
File ".../venv/lib/python3.6/site-packages/django/db/backends/base/schema.py", line 1027, in _constraint_names
constraints = self.connection.introspection.get_constraints(cursor, model._meta.db_table)
File ".../venv/lib/python3.6/site-
packages/django/db/backends/postgresql/introspection.py", line 158, in get_constraints
""", ["public", table_name])
File ".../venv/lib/python3.6/site-packages/django/db/backends/utils.py",
line 100, in execute
return super().execute(sql, params)
File


".../venv/lib/python3.6/site-packages/django/db/backends/utils.py", line 68, in execute
return self._execute_with_wrappers(sql, params, many=False, executor=self._execute)
File ".../venv/lib/python3.6/site-packages/django/db/backends/utils.py", line 77, in _execute_with_wrappers
return executor(sql, params, many, context)
File ".../venv/lib/python3.6/site-packages/django/db/backends/utils.py", line 85, in _execute
return self.cursor.execute(sql, params)
File "/.../venv/lib/python3.6/site-packages/django/db/utils.py", line 89, in __exit__
raise dj_exc_value.with_traceback(traceback) from exc_value
File ".../venv/lib/python3.6/site-packages/django/db/backends/utils.py", line 85, in _execute
return self.cursor.execute(sql, params)
django.db.utils.ProgrammingError: syntax error at or near "WITH
ORDINALITY"
LINE 6: FROM unnest(c.conkey) WITH ORDINALITY co...
^


Anyway, if after that I try again to make migrations, got the message that I don't have migrations. So, Django did the job, But this error is here constantly when I try to migrate, I am really wondering why. I tried to google it, but I got nothing.










share|improve this question




















  • 1




    remove migrations folder in each app.
    – Mohammad Ali
    Aug 18 at 7:07






  • 1




    @LeLouch You are kidding me, right? I know to read. :D That is in utils.py file, which does not file that I created or changed. Something that I have done, probably cause that error in Django automatic created file - utils.py
    – Neven
    Aug 18 at 20:08






  • 1




    @MohammadAli Thank you again !!! I couldn't be grateful more! Please, write that as a response and I will accept it. :)
    – Neven
    Aug 18 at 20:12















up vote
1
down vote

favorite
1












I have a problem (at least I think). I am new in all this, so I apologize If I ask something stupid.
I have some site, which is working normally. When I try to make migrations ( python manage.py makemigrations), everything passed ok, I got the message of how many models new I have, etc. But, when I run after that migrate, I got the following output:



Operations to perform:
Apply all migrations: admin, auth, comments, contenttypes, news, sessions
Running migrations:
Applying comments.0003_auto_20180816_2158...Traceback (most recent call last):
File "../venv/lib/python3.6/site-packages/django/db/backends/utils.py", line 85, in _execute
return self.cursor.execute(sql, params)
psycopg2.ProgrammingError: syntax error at or near "WITH ORDINALITY"
LINE 6: FROM unnest(c.conkey) WITH ORDINALITY co...
^


The above exception was the direct cause of the following exception:

Traceback (most recent call last):
File "manage.py", line 15, in <module>
execute_from_command_line(sys.argv)
File ".../venv/lib/python3.6/site-packages/django/core/management/__init__.py", line 381, in execute_from_command_line
utility.execute()
File ".../venv/lib/python3.6/site-packages/django/core/management/__init__.py", line 375, in execute
self.fetch_command(subcommand).run_from_argv(self.argv)
File ".../venv/lib/python3.6/site-packages/django/core/management/base.py", line 316, in run_from_argv
self.execute(*args, **cmd_options)
File
".../venv/lib/python3.6/site-packages/django/core/management/base.py", line 353, in execute
output = self.handle(*args, **options)
File
".../venv/lib/python3.6/site-packages/django/core/management/base.py", line 83, in wrapped
res = handle_func(*args, **kwargs)
File ".../venv/lib/python3.6/site-
packages/django/core/management/commands/migrate.py", line 203, in handle
fake_initial=fake_initial,
File


".../venv/lib/python3.6/site-
packages/django/db/backends/base/schema.py", line 531, in _alter_field
fk_names = self._constraint_names(model, [old_field.column],
foreign_key=True)
File ".../venv/lib/python3.6/site-packages/django/db/backends/base/schema.py", line 1027, in _constraint_names
constraints = self.connection.introspection.get_constraints(cursor, model._meta.db_table)
File ".../venv/lib/python3.6/site-
packages/django/db/backends/postgresql/introspection.py", line 158, in get_constraints
""", ["public", table_name])
File ".../venv/lib/python3.6/site-packages/django/db/backends/utils.py",
line 100, in execute
return super().execute(sql, params)
File


".../venv/lib/python3.6/site-packages/django/db/backends/utils.py", line 68, in execute
return self._execute_with_wrappers(sql, params, many=False, executor=self._execute)
File ".../venv/lib/python3.6/site-packages/django/db/backends/utils.py", line 77, in _execute_with_wrappers
return executor(sql, params, many, context)
File ".../venv/lib/python3.6/site-packages/django/db/backends/utils.py", line 85, in _execute
return self.cursor.execute(sql, params)
File "/.../venv/lib/python3.6/site-packages/django/db/utils.py", line 89, in __exit__
raise dj_exc_value.with_traceback(traceback) from exc_value
File ".../venv/lib/python3.6/site-packages/django/db/backends/utils.py", line 85, in _execute
return self.cursor.execute(sql, params)
django.db.utils.ProgrammingError: syntax error at or near "WITH
ORDINALITY"
LINE 6: FROM unnest(c.conkey) WITH ORDINALITY co...
^


Anyway, if after that I try again to make migrations, got the message that I don't have migrations. So, Django did the job, But this error is here constantly when I try to migrate, I am really wondering why. I tried to google it, but I got nothing.










share|improve this question




















  • 1




    remove migrations folder in each app.
    – Mohammad Ali
    Aug 18 at 7:07






  • 1




    @LeLouch You are kidding me, right? I know to read. :D That is in utils.py file, which does not file that I created or changed. Something that I have done, probably cause that error in Django automatic created file - utils.py
    – Neven
    Aug 18 at 20:08






  • 1




    @MohammadAli Thank you again !!! I couldn't be grateful more! Please, write that as a response and I will accept it. :)
    – Neven
    Aug 18 at 20:12













up vote
1
down vote

favorite
1









up vote
1
down vote

favorite
1






1





I have a problem (at least I think). I am new in all this, so I apologize If I ask something stupid.
I have some site, which is working normally. When I try to make migrations ( python manage.py makemigrations), everything passed ok, I got the message of how many models new I have, etc. But, when I run after that migrate, I got the following output:



Operations to perform:
Apply all migrations: admin, auth, comments, contenttypes, news, sessions
Running migrations:
Applying comments.0003_auto_20180816_2158...Traceback (most recent call last):
File "../venv/lib/python3.6/site-packages/django/db/backends/utils.py", line 85, in _execute
return self.cursor.execute(sql, params)
psycopg2.ProgrammingError: syntax error at or near "WITH ORDINALITY"
LINE 6: FROM unnest(c.conkey) WITH ORDINALITY co...
^


The above exception was the direct cause of the following exception:

Traceback (most recent call last):
File "manage.py", line 15, in <module>
execute_from_command_line(sys.argv)
File ".../venv/lib/python3.6/site-packages/django/core/management/__init__.py", line 381, in execute_from_command_line
utility.execute()
File ".../venv/lib/python3.6/site-packages/django/core/management/__init__.py", line 375, in execute
self.fetch_command(subcommand).run_from_argv(self.argv)
File ".../venv/lib/python3.6/site-packages/django/core/management/base.py", line 316, in run_from_argv
self.execute(*args, **cmd_options)
File
".../venv/lib/python3.6/site-packages/django/core/management/base.py", line 353, in execute
output = self.handle(*args, **options)
File
".../venv/lib/python3.6/site-packages/django/core/management/base.py", line 83, in wrapped
res = handle_func(*args, **kwargs)
File ".../venv/lib/python3.6/site-
packages/django/core/management/commands/migrate.py", line 203, in handle
fake_initial=fake_initial,
File


".../venv/lib/python3.6/site-
packages/django/db/backends/base/schema.py", line 531, in _alter_field
fk_names = self._constraint_names(model, [old_field.column],
foreign_key=True)
File ".../venv/lib/python3.6/site-packages/django/db/backends/base/schema.py", line 1027, in _constraint_names
constraints = self.connection.introspection.get_constraints(cursor, model._meta.db_table)
File ".../venv/lib/python3.6/site-
packages/django/db/backends/postgresql/introspection.py", line 158, in get_constraints
""", ["public", table_name])
File ".../venv/lib/python3.6/site-packages/django/db/backends/utils.py",
line 100, in execute
return super().execute(sql, params)
File


".../venv/lib/python3.6/site-packages/django/db/backends/utils.py", line 68, in execute
return self._execute_with_wrappers(sql, params, many=False, executor=self._execute)
File ".../venv/lib/python3.6/site-packages/django/db/backends/utils.py", line 77, in _execute_with_wrappers
return executor(sql, params, many, context)
File ".../venv/lib/python3.6/site-packages/django/db/backends/utils.py", line 85, in _execute
return self.cursor.execute(sql, params)
File "/.../venv/lib/python3.6/site-packages/django/db/utils.py", line 89, in __exit__
raise dj_exc_value.with_traceback(traceback) from exc_value
File ".../venv/lib/python3.6/site-packages/django/db/backends/utils.py", line 85, in _execute
return self.cursor.execute(sql, params)
django.db.utils.ProgrammingError: syntax error at or near "WITH
ORDINALITY"
LINE 6: FROM unnest(c.conkey) WITH ORDINALITY co...
^


Anyway, if after that I try again to make migrations, got the message that I don't have migrations. So, Django did the job, But this error is here constantly when I try to migrate, I am really wondering why. I tried to google it, but I got nothing.










share|improve this question















I have a problem (at least I think). I am new in all this, so I apologize If I ask something stupid.
I have some site, which is working normally. When I try to make migrations ( python manage.py makemigrations), everything passed ok, I got the message of how many models new I have, etc. But, when I run after that migrate, I got the following output:



Operations to perform:
Apply all migrations: admin, auth, comments, contenttypes, news, sessions
Running migrations:
Applying comments.0003_auto_20180816_2158...Traceback (most recent call last):
File "../venv/lib/python3.6/site-packages/django/db/backends/utils.py", line 85, in _execute
return self.cursor.execute(sql, params)
psycopg2.ProgrammingError: syntax error at or near "WITH ORDINALITY"
LINE 6: FROM unnest(c.conkey) WITH ORDINALITY co...
^


The above exception was the direct cause of the following exception:

Traceback (most recent call last):
File "manage.py", line 15, in <module>
execute_from_command_line(sys.argv)
File ".../venv/lib/python3.6/site-packages/django/core/management/__init__.py", line 381, in execute_from_command_line
utility.execute()
File ".../venv/lib/python3.6/site-packages/django/core/management/__init__.py", line 375, in execute
self.fetch_command(subcommand).run_from_argv(self.argv)
File ".../venv/lib/python3.6/site-packages/django/core/management/base.py", line 316, in run_from_argv
self.execute(*args, **cmd_options)
File
".../venv/lib/python3.6/site-packages/django/core/management/base.py", line 353, in execute
output = self.handle(*args, **options)
File
".../venv/lib/python3.6/site-packages/django/core/management/base.py", line 83, in wrapped
res = handle_func(*args, **kwargs)
File ".../venv/lib/python3.6/site-
packages/django/core/management/commands/migrate.py", line 203, in handle
fake_initial=fake_initial,
File


".../venv/lib/python3.6/site-
packages/django/db/backends/base/schema.py", line 531, in _alter_field
fk_names = self._constraint_names(model, [old_field.column],
foreign_key=True)
File ".../venv/lib/python3.6/site-packages/django/db/backends/base/schema.py", line 1027, in _constraint_names
constraints = self.connection.introspection.get_constraints(cursor, model._meta.db_table)
File ".../venv/lib/python3.6/site-
packages/django/db/backends/postgresql/introspection.py", line 158, in get_constraints
""", ["public", table_name])
File ".../venv/lib/python3.6/site-packages/django/db/backends/utils.py",
line 100, in execute
return super().execute(sql, params)
File


".../venv/lib/python3.6/site-packages/django/db/backends/utils.py", line 68, in execute
return self._execute_with_wrappers(sql, params, many=False, executor=self._execute)
File ".../venv/lib/python3.6/site-packages/django/db/backends/utils.py", line 77, in _execute_with_wrappers
return executor(sql, params, many, context)
File ".../venv/lib/python3.6/site-packages/django/db/backends/utils.py", line 85, in _execute
return self.cursor.execute(sql, params)
File "/.../venv/lib/python3.6/site-packages/django/db/utils.py", line 89, in __exit__
raise dj_exc_value.with_traceback(traceback) from exc_value
File ".../venv/lib/python3.6/site-packages/django/db/backends/utils.py", line 85, in _execute
return self.cursor.execute(sql, params)
django.db.utils.ProgrammingError: syntax error at or near "WITH
ORDINALITY"
LINE 6: FROM unnest(c.conkey) WITH ORDINALITY co...
^


Anyway, if after that I try again to make migrations, got the message that I don't have migrations. So, Django did the job, But this error is here constantly when I try to migrate, I am really wondering why. I tried to google it, but I got nothing.







python django






share|improve this question















share|improve this question













share|improve this question




share|improve this question








edited Nov 10 at 15:41









argo

2,6852827




2,6852827










asked Aug 17 at 22:35









Neven

806




806








  • 1




    remove migrations folder in each app.
    – Mohammad Ali
    Aug 18 at 7:07






  • 1




    @LeLouch You are kidding me, right? I know to read. :D That is in utils.py file, which does not file that I created or changed. Something that I have done, probably cause that error in Django automatic created file - utils.py
    – Neven
    Aug 18 at 20:08






  • 1




    @MohammadAli Thank you again !!! I couldn't be grateful more! Please, write that as a response and I will accept it. :)
    – Neven
    Aug 18 at 20:12














  • 1




    remove migrations folder in each app.
    – Mohammad Ali
    Aug 18 at 7:07






  • 1




    @LeLouch You are kidding me, right? I know to read. :D That is in utils.py file, which does not file that I created or changed. Something that I have done, probably cause that error in Django automatic created file - utils.py
    – Neven
    Aug 18 at 20:08






  • 1




    @MohammadAli Thank you again !!! I couldn't be grateful more! Please, write that as a response and I will accept it. :)
    – Neven
    Aug 18 at 20:12








1




1




remove migrations folder in each app.
– Mohammad Ali
Aug 18 at 7:07




remove migrations folder in each app.
– Mohammad Ali
Aug 18 at 7:07




1




1




@LeLouch You are kidding me, right? I know to read. :D That is in utils.py file, which does not file that I created or changed. Something that I have done, probably cause that error in Django automatic created file - utils.py
– Neven
Aug 18 at 20:08




@LeLouch You are kidding me, right? I know to read. :D That is in utils.py file, which does not file that I created or changed. Something that I have done, probably cause that error in Django automatic created file - utils.py
– Neven
Aug 18 at 20:08




1




1




@MohammadAli Thank you again !!! I couldn't be grateful more! Please, write that as a response and I will accept it. :)
– Neven
Aug 18 at 20:12




@MohammadAli Thank you again !!! I couldn't be grateful more! Please, write that as a response and I will accept it. :)
– Neven
Aug 18 at 20:12












2 Answers
2






active

oldest

votes

















up vote
1
down vote



accepted










First, you must remove migration folders in each app



then, you can use migration commands



python manage.py makemigrations
python manage.py migrate





share|improve this answer

















  • 2




    This would won't work on many corner cases. Kindly avoid deleting migration folder for any migration issue. I used to do the same mistake until I got trapped on this. I'm writing a detailed answer on how to do migration and solve migration issues, which I has helped me till date.
    – argo
    Aug 19 at 4:33


















up vote
4
down vote













Whenever you are adding any new field and facing migrate error.



Kindly follow these steps:




  • Delete all migration files(not the migration folder, keep the init.py file

  • Truncate the _django_migrations_ table

  • comment the new field which is to be added from the models.py. (Do make sure this step otherwise django will throw error when you would follow the below steps)

  • run python manage.py makemigrations

  • run python manage.py migrate --fake

  • Uncomment the new field to be added

  • run python manage.py makemigrations

  • run python manage.py migrate


Generally these steps solve any kind of migration problem.



P.S. : When you face problem in only one app, I would recommend to delete entries of that particular app from the django_migrations table






share|improve this answer





















  • Thank you @agro ! I thumbed up your response and confirmed Mohammad because his comment helped me a day ago. But your response is more detailed and I hope it will have so much more thumbs up!
    – Neven
    Aug 19 at 19:57











Your Answer






StackExchange.ifUsing("editor", function () {
StackExchange.using("externalEditor", function () {
StackExchange.using("snippets", function () {
StackExchange.snippets.init();
});
});
}, "code-snippets");

StackExchange.ready(function() {
var channelOptions = {
tags: "".split(" "),
id: "1"
};
initTagRenderer("".split(" "), "".split(" "), channelOptions);

StackExchange.using("externalEditor", function() {
// Have to fire editor after snippets, if snippets enabled
if (StackExchange.settings.snippets.snippetsEnabled) {
StackExchange.using("snippets", function() {
createEditor();
});
}
else {
createEditor();
}
});

function createEditor() {
StackExchange.prepareEditor({
heartbeatType: 'answer',
convertImagesToLinks: true,
noModals: true,
showLowRepImageUploadWarning: true,
reputationToPostImages: 10,
bindNavPrevention: true,
postfix: "",
imageUploader: {
brandingHtml: "Powered by u003ca class="icon-imgur-white" href="https://imgur.com/"u003eu003c/au003e",
contentPolicyHtml: "User contributions licensed under u003ca href="https://creativecommons.org/licenses/by-sa/3.0/"u003ecc by-sa 3.0 with attribution requiredu003c/au003e u003ca href="https://stackoverflow.com/legal/content-policy"u003e(content policy)u003c/au003e",
allowUrls: true
},
onDemand: true,
discardSelector: ".discard-answer"
,immediatelyShowMarkdownHelp:true
});


}
});














 

draft saved


draft discarded


















StackExchange.ready(
function () {
StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f51903606%2ferrors-when-i-try-to-migrate-in-django2%23new-answer', 'question_page');
}
);

Post as a guest















Required, but never shown

























2 Answers
2






active

oldest

votes








2 Answers
2






active

oldest

votes









active

oldest

votes






active

oldest

votes








up vote
1
down vote



accepted










First, you must remove migration folders in each app



then, you can use migration commands



python manage.py makemigrations
python manage.py migrate





share|improve this answer

















  • 2




    This would won't work on many corner cases. Kindly avoid deleting migration folder for any migration issue. I used to do the same mistake until I got trapped on this. I'm writing a detailed answer on how to do migration and solve migration issues, which I has helped me till date.
    – argo
    Aug 19 at 4:33















up vote
1
down vote



accepted










First, you must remove migration folders in each app



then, you can use migration commands



python manage.py makemigrations
python manage.py migrate





share|improve this answer

















  • 2




    This would won't work on many corner cases. Kindly avoid deleting migration folder for any migration issue. I used to do the same mistake until I got trapped on this. I'm writing a detailed answer on how to do migration and solve migration issues, which I has helped me till date.
    – argo
    Aug 19 at 4:33













up vote
1
down vote



accepted







up vote
1
down vote



accepted






First, you must remove migration folders in each app



then, you can use migration commands



python manage.py makemigrations
python manage.py migrate





share|improve this answer












First, you must remove migration folders in each app



then, you can use migration commands



python manage.py makemigrations
python manage.py migrate






share|improve this answer












share|improve this answer



share|improve this answer










answered Aug 19 at 4:05









Mohammad Ali

936314




936314








  • 2




    This would won't work on many corner cases. Kindly avoid deleting migration folder for any migration issue. I used to do the same mistake until I got trapped on this. I'm writing a detailed answer on how to do migration and solve migration issues, which I has helped me till date.
    – argo
    Aug 19 at 4:33














  • 2




    This would won't work on many corner cases. Kindly avoid deleting migration folder for any migration issue. I used to do the same mistake until I got trapped on this. I'm writing a detailed answer on how to do migration and solve migration issues, which I has helped me till date.
    – argo
    Aug 19 at 4:33








2




2




This would won't work on many corner cases. Kindly avoid deleting migration folder for any migration issue. I used to do the same mistake until I got trapped on this. I'm writing a detailed answer on how to do migration and solve migration issues, which I has helped me till date.
– argo
Aug 19 at 4:33




This would won't work on many corner cases. Kindly avoid deleting migration folder for any migration issue. I used to do the same mistake until I got trapped on this. I'm writing a detailed answer on how to do migration and solve migration issues, which I has helped me till date.
– argo
Aug 19 at 4:33












up vote
4
down vote













Whenever you are adding any new field and facing migrate error.



Kindly follow these steps:




  • Delete all migration files(not the migration folder, keep the init.py file

  • Truncate the _django_migrations_ table

  • comment the new field which is to be added from the models.py. (Do make sure this step otherwise django will throw error when you would follow the below steps)

  • run python manage.py makemigrations

  • run python manage.py migrate --fake

  • Uncomment the new field to be added

  • run python manage.py makemigrations

  • run python manage.py migrate


Generally these steps solve any kind of migration problem.



P.S. : When you face problem in only one app, I would recommend to delete entries of that particular app from the django_migrations table






share|improve this answer





















  • Thank you @agro ! I thumbed up your response and confirmed Mohammad because his comment helped me a day ago. But your response is more detailed and I hope it will have so much more thumbs up!
    – Neven
    Aug 19 at 19:57















up vote
4
down vote













Whenever you are adding any new field and facing migrate error.



Kindly follow these steps:




  • Delete all migration files(not the migration folder, keep the init.py file

  • Truncate the _django_migrations_ table

  • comment the new field which is to be added from the models.py. (Do make sure this step otherwise django will throw error when you would follow the below steps)

  • run python manage.py makemigrations

  • run python manage.py migrate --fake

  • Uncomment the new field to be added

  • run python manage.py makemigrations

  • run python manage.py migrate


Generally these steps solve any kind of migration problem.



P.S. : When you face problem in only one app, I would recommend to delete entries of that particular app from the django_migrations table






share|improve this answer





















  • Thank you @agro ! I thumbed up your response and confirmed Mohammad because his comment helped me a day ago. But your response is more detailed and I hope it will have so much more thumbs up!
    – Neven
    Aug 19 at 19:57













up vote
4
down vote










up vote
4
down vote









Whenever you are adding any new field and facing migrate error.



Kindly follow these steps:




  • Delete all migration files(not the migration folder, keep the init.py file

  • Truncate the _django_migrations_ table

  • comment the new field which is to be added from the models.py. (Do make sure this step otherwise django will throw error when you would follow the below steps)

  • run python manage.py makemigrations

  • run python manage.py migrate --fake

  • Uncomment the new field to be added

  • run python manage.py makemigrations

  • run python manage.py migrate


Generally these steps solve any kind of migration problem.



P.S. : When you face problem in only one app, I would recommend to delete entries of that particular app from the django_migrations table






share|improve this answer












Whenever you are adding any new field and facing migrate error.



Kindly follow these steps:




  • Delete all migration files(not the migration folder, keep the init.py file

  • Truncate the _django_migrations_ table

  • comment the new field which is to be added from the models.py. (Do make sure this step otherwise django will throw error when you would follow the below steps)

  • run python manage.py makemigrations

  • run python manage.py migrate --fake

  • Uncomment the new field to be added

  • run python manage.py makemigrations

  • run python manage.py migrate


Generally these steps solve any kind of migration problem.



P.S. : When you face problem in only one app, I would recommend to delete entries of that particular app from the django_migrations table







share|improve this answer












share|improve this answer



share|improve this answer










answered Aug 19 at 4:32









argo

2,6852827




2,6852827












  • Thank you @agro ! I thumbed up your response and confirmed Mohammad because his comment helped me a day ago. But your response is more detailed and I hope it will have so much more thumbs up!
    – Neven
    Aug 19 at 19:57


















  • Thank you @agro ! I thumbed up your response and confirmed Mohammad because his comment helped me a day ago. But your response is more detailed and I hope it will have so much more thumbs up!
    – Neven
    Aug 19 at 19:57
















Thank you @agro ! I thumbed up your response and confirmed Mohammad because his comment helped me a day ago. But your response is more detailed and I hope it will have so much more thumbs up!
– Neven
Aug 19 at 19:57




Thank you @agro ! I thumbed up your response and confirmed Mohammad because his comment helped me a day ago. But your response is more detailed and I hope it will have so much more thumbs up!
– Neven
Aug 19 at 19:57


















 

draft saved


draft discarded



















































 


draft saved


draft discarded














StackExchange.ready(
function () {
StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f51903606%2ferrors-when-i-try-to-migrate-in-django2%23new-answer', 'question_page');
}
);

Post as a guest















Required, but never shown





















































Required, but never shown














Required, but never shown












Required, but never shown







Required, but never shown

































Required, but never shown














Required, but never shown












Required, but never shown







Required, but never shown







Popular posts from this blog

Full-time equivalent

Bicuculline

さくらももこ