My Blog Posts disappear everytime I make migrations. Heroku-Django blog - python

So I made a blog with django and hosted it on heroku(Free version), and every time I make new migrations, the posts that I uploaded earlier would disappear and left are the trial posts which I uploaded on my machine for testing. I don't understand why this is happening.
These are the commands I used.
heroku run python manage.py makemigrations
and then
heroku run python manae.py migrate
I don't think that it is any of the code that is throwing this problem. But if you need to check any of the files, I'll attach'em . Please help.

It's probable that you are still using SQLite, which is stored on disk. Django apps start off with SQLite by default, so if you haven't consciously changed your database that's certainly what you're using. Heroku's active storage is "ephemeral", meaning it goes away when you restart your dynos. This means that while your database will still look the same (because you haven't changed your models or migration files, after all), there won't be any data in it except stuff added after the dyno restarts.
The solution is to use a different database, such as PostGreSQL, that has its own server and lives independent of your Heroku dynos. You can learn more here.

Related

Cannot makemigrations on Django Settings already configured error

I'm a new django developer and I recently started a project, and am trying to get the database up and running.
For background: we are using a mysql database for storage, and the settings are configured for it. Using an Unbuntu DO server. I have also been using the virtual environment to run the commands below.
When we initially created the project we ran the makemigrations command, which populated the database with django tables, but not the Models, as we had not made any Models yet. I've now uploaded the Model code, however I could not make any new migrations, I got the error RuntimeError("Settings already configured").
According to this tutorial which I was following (https://www.geekinsta.com/how-to-customize-django-user-model/) some errors are normal and required me to delete and recreate the mysql database (which I did, it has the same name), and clear past migrations (the app/migrations/pycache is now empty). However I'm still experiencing the same error ("Settings already configured").
How can I fix this? I need to successfully run the makemigrations and migrate commands to populate the database. The new database and pycache are empty after I attempted the commands again. Thanks for any and all help.

Django migrations not applying after moving from test PC to production server/DB

I am unable to run the inital migrations in my django project on my production server.
I started working on my Django app on my computer with a sqlite db. I was able to run the initial migrations (auth, admin, etc.) and they created tables in my sqlite db with no problem. I was also able to get tables created for the models in my app.
Today I moved the same django project to my webfaction server via git and I am unable to get my MySQL db populated with tables at all. As soon as I created the db, I ran migrate but it said there were no migrations to apply. I tried deleting the migrations folder in my app, but that didn't help at all, probably because there is no django_migrations table to compare any migrations against.
It seems as if the initial migrations are stored where django is installed. This is not part of my git repo, so anything there that might indicate whether the migrations have been made wouldn't be pulled over.
I tried running python manage.py migrate admin
And the same thing with auth, but it did't work
I'm not really sure what the proper way is to go about getting these initial migrations to run again so that I have the proper auth and admin tables in my db. Any help would be appreciated.
This is Django 2.1.7 and Python 3.5
Thanks, Yongjin and Nagesh. By asking me to post my DB settings, you made me realize that I hadn't changed the name of the DB from the project I copied the settings from. Much appreciated!

Migrations error in Django after moving to new server

I'm developing a Django 1.8 application locally and having reached a certain point a few days ago, I uploaded the app to a staging server, ran migrations, imported the sql dump, etc. and all was fine.
I've since resumed local development which included the creation of a new model, and changing some columns on an existing model. I ran the migrations locally with success, but after rsync-ing my files to the staging server, I get a 'relation already exists' error when running manage.py migrate. And when I visit the admin page for the new model, I get a 'column does not exist' error.
It seems as though the migrations for this model were partially successful but I cannot migrate the entirety of the model schema. I've tried commenting out parts of the migration files, but was not successful. Would it be possible to create the missing columns via psql? Or is there some way of determining what is missing and then manually write a migration to create the missing database structure?
I'm using Django 1.8.6, Python 3.4.3, and PostgreSQL 9.3.6. Any advice on this would be great. Thanks.
Try running migrate --fake-initial since you're getting the "relation already exists" error. Failing that, I would manually back up each one of my migration folders, remove them from the server, then re-generate migration files for each app and run them all again from scratch (i.e., the initial makemigrations).

What's the right way to handle an initial database migration in Django?

I'm in the process of preparing a Django application for its initial production release, and I have deployed development instances of it in a few different environments. One thing that I can't quite get happening as smoothly as I'd like is the initial database migration. Given a fresh installation of Django, a deployment of my application from version control, and a clean database, manage.py migrate will handle the initial creation of all tables (both Django's and my models'). That's great, but it doesn't actually create the initial migration files for my apps. This leads to a problem down the road when I need to deploy code changes that require a new database migration, because there's no basis for Django to compute the deltas.
I've tried running manage.py makemigrations as the first step in the deployment, in the hopes that it would create the migration files, but it reports that there are no changes to migrate. The only way I've found to get the baseline state that I need is to run manage.py makemigrations [appname] for each of my apps. Shouldn't makemigrations, called without a specific app name, pick up all the installed apps and create their migrations? Where am I going wrong?
You're going wrong at the very end -- yes, you do need to call manage.py makemigrations <appname> for each of your apps once. It's not automatically done for all apps.
Presumably that is because Django has no way of knowing if that is what you want to do (especially if some apps were downloaded from PyPI, etc). And a single command per app can't really be an extreme amount of work, right?

Django unable to open sqlite on SOME queries only?

I have had no troubles locally, but pushing a new project to an existing machine (one running plenty of other django apps without trouble) gave this:
OperationalError: unable to open database file
What is more perplexing is:
The sqlite file is read-write for all
This error only happens on some queries! Other's are fine.
In a fresh db after running syncdb, my views work, but /admin/ triggers this.
If I loaddata for some of my apps from data dumped from my local machine, some of the apps trigger this in my views, and others do not.
I can find no correlation between any of the things that seem to trigger this.
Why would it fail to open the database, aside from permissions?
Write access on the directory. I thought i checked that first :-/

Categories