1

I'm having trouble with my Django-app that's been deployed.

It was working fine but I had to do a minor modification (augmented the max_length) of a Charfield of some model. I did migrations and everything was working fine in the local version.

Then I commited the changes without a problem and the mentioned field of the web version now accepts more characters, as expected, but whenever I click the save button a Server Error rises.

I assume I have to do some kind of migration/DB update for the web version but I don't seem to find how.

(I'm working with Django 1.11, postgresql 9.6, and DigitalOcean).

EDIT

I've just realized that the 'minor modification' also included a field deletion in the model.

1 Answer 1

3

Short answer

You have to run

python manage.py migrate

on the server, too. Before you do that, make sure all migration scripts you have locally are also present on the server.

Explanation

After changing the model, you probably locally ran

python manage.py makemigrations

This creates migration scripts that'll transform database schema accordingly. Hopefully, you've committed these newly created scripts to Git, together with the changed model. (If not, you can still do so now.)

after running makemigrations (either before or after committing, that shouldn't matter), you've probably locally ran

python manage.py migrate

This applies the migration scripts to the database that haven't been applied to it, yet. (The information which ones have already been applied is stored in the database itself.)

You probably (and hopefully) haven't checked in your local database into Git, so when you pushed your tracked changes to a remote repo and pulled them down on your server (or however else the new Git revisions got there), the changes to the server database haven't happened, yet. So you have to repeat the last local step (migrate) on the server.

Further reading

For more information, refer to the Django 1.11 documentation w.r.t. migrations. (You can e.g. limit migration creation or migration application to a single Django app, instead of the whole Django project.) To get the grip of these things, I can recomment the free Django Girls tutorial.

Sign up to request clarification or add additional context in comments.

4 Comments

Thx for your answer. I ran 'migrate' from the server already and an AttributeError that I cannot trace back rises. Before that I did ran 'makemigrations --merge', as the server itself suggested...
Did migrate result in the AttributeError (then it probably couldn't complete and left your database with the old schema) or did the AttributeError occur in the application after the migration had successfully run through? I either case, if you can't interpret the error message yourself (or with the help of a rubber duck) you might want to ask a separate question about it. If so, be sure to include the complete error message and complete stack trace. (Read them before, and ensure you don't publish any sensitive data!)
The AttributeErrorshowed up when I ran python manage.py migrate. Previously I ran python manage.py makemigration --merge.
I have just realized that the 'minor modification' also included a deleted field.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.