简体   繁体   中英

Django migrate works but doesn't reflect on live site

I made some updates to a project: add 1 admin model, add 1 template

I'm using wagtail. I pulled the updates to my server, ran migrations, got success. I restart nginx and gunicorn, I even rebooted the server.

When I go to the wagtail admin, my adminmodel is missing (it exists locally). when I go to create a new page, my template is available, but when I select it I get taken to a wagtail 404 page.

Ubuntu 20.04
ngnix
gunicorn
django/wagtail
digital ocean vpc
digital ocean postgres database cluster

The site works like normal, only a template is available I can't select, and the Model, that migrated, isn't available and isn't showing up in admin. my local version is working perfectly, with no differences. it seems like the server is both updating and not updating. I don't get it. running makemigrations or migrate returns no changes. even when running on the specific app. Do I need to do something to rebot the database?

Listen it looks like caching issue with Nginx. Try clearing the cache.

I have 2 settings files: dev.py, production.py

dev.py is connected to a sqlite3 db and production is connected to the digitalocean postgres cluster.

python manage.py automatically uses dev.py (at least in my setup) so my migrations were working, but they were targeting an old copy of the sqlite.db I had on the server, or perhaps created one as it does when one doesn't exist. Either way, the live site runs on the production.py settings and this is why the changes were being made but not reflecting.

The correct way to run migrations when you have a production.py file is similar to:

python manage.py migrate --settings=<settings app>.<settings folder>.production

I'm also going to add that I found that you need to collectstatic each time you update your css stylesheet. that is a little tedious, and maybe I am missing an automation step, but considering that is the case, just to be safe, I run like this:

python manage.py collectstatic --settings=<settings app>.<settings folder>.production

It doesn't cause any issues and it works, so I use the --settings flag to be safe.

git pull
python manage.py migrate --settings=app.settings.production
python manage.py collectstatic --settings=app.settings.production
sudo systemctl restart ngix
sudo systemctl restart gunicorn

I don't know that restarting ngix is necessary except it solved something with my static files updating I believe.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM