Postgres data_type modification in Django - django

The web application I'm working on in Django ran into a bug when I attempted modifying the data type of a field(column). I got some advice to drop/delete the table which didn't end up very well. Now I'm stuck. I tried creating a new table manually but its still giving me the same error. I tried changing the name of the previous table from its models.py, but that didn't work either. The website is giving me this error, 'Server Error (500),' as it is in production mode and the debug is set to false. I've tried. 'python manage.py makemigrations,' but it says no changes. Also, 'python manage.py migrate,' but that gives an error.

Related

Table already exists when I run pytest on Django project

This is a very simple issue but may take a long time resolve if you fail to look at the correct point. Especially there's not much content online to hint the source of the problem.
I have a Django project of version 3.2.5.
I created a new model: app.model. Then I ran python manage.py makemigrations app command.
When I ran the tests via pytest, I got the following errors:
E psycopg2.errors.DuplicateTable: relation "app_model" already exists
E django.db.utils.ProgrammingError: relation "app_model" already exists
However there's no such table neither on my local database nor in test database which is created from scratch.
I pushed my code on a branch to Github and build succeeded online with no problems. However my test suite complained about this existing table. I ran python manage.py migrate app and it worked.
I realized it is a problem caused by using pytest with --reuse-db argument. It doesn't ask you to delete an orphan test database in this case, it reuses it.
Instead of using pytest, when I run python manage.py test, I got the following prompt:
Type 'yes' if you would like to try deleting the test database 'test_project', or 'no' to cancel: Got an error creating the test database: database "test_project" already exists
I typed yes, the orphan test_project database was deleted & re-created from scratch and the errors disappeared.
Another solution would be using --create-db with pytest command or adding this option to the pytest.ini file.

Django SQLite on Heroku doesn't recognize any of the changed models and throws a "relation doesn't exist" error

I changed the name of several models on Django. Successfully ran makemigrations and migrate. I can interact with the SQLite directly as admin or through requests on localhost.
before changing the tables I had deployed to Heroku and it was working. when I changed the model names and pushed to Heroku (after successfully running on localhost) I get issues. When I login as admin to the site (on Heroku) I can interact with tables like User and Token, but not with the newly updated models. as soon as I click on them I get bellow error. when I click on add to these models, the columns appear but as soon as I hit save I get below error as well.
ProgrammingError at /admin/app_name/model_name/
relation "app_name_model_name" does not exist
LINE 1: SELECT COUNT(*) AS "__count" FROM "app_name_model_name"
I kept the Debug=True to see what's going on otherwise I get "500 Internal Server Error". I have added heroku's site as "ALLOWED_HOSTS".
When I was trying to make the migrations work, I had delete the files on the migration folder. not sure if there is a similar process on Heroku or if I'm missing something else?
By the way I have ran the migration commands using "heroku run bash" too. also, some of the models only had name changes, some had field updates too, but all of them throw the same error on Heroku.
I removed the app entirely from Heroku and recreated. it's working now.

Django: Heroku deploy not migrating properly

I'm new to Heroku and I am trying to do my first deploy with a change in my models. Now I already have some important stuff in my app's database that I don't want to lose (I'm using PostgresSQL).
Anyway, I did those few improvement to my app's model and it works alright locally, but when I try to deploy it just gives me the
Internal Server Error: /lares/
ProgrammingError at /lares/
column lares_imovel.referencia does not exist
I am used to throwing makemigrations and migrate locally and than just git push heroku master
Anyway, I also tried the heroku run python manage.py migrate afterwards, but I get the same result every time.
I deleted all my migrations files and created them again for this particular app, still it works locally and the issue remains on production.
Do you guys have any idea why this is happening?
I don't know if any of my code is necessary, I'm pretty sure the problem is not there, but if requested I can post it here.
Thanks!

Graphite Web Error Log, OperationalError: no such table: auth_user

I have a problem with starting graphite web interface, using apache2. I get 500 Internal error, the screenshot of my log is below. I am new to this website and also to this software. My question might be too simple but, I have spent a lot of time on this. Thanks..
error log:
It looks like the database has not yet been created. You can do so by running:
sudo -u _graphite graphite-manage syncdb --noinput
and that should clear up the 500 error. This is a minimum to get started with Graphite, using the SQLite database. It is possible to configure an alternate database in the local_settings.py file, in which case the above command is not necessary. But with the default configuration, which uses SQLite as the back-end, this command should get you past the error.
Source: https://ianunruh.com/2014/05/monitor-everything-part-4.html

Why would GeoDjango and/or PostGIS retain the errors thrown after the error has been fixed?

I'm playing with GeoDjango and PostGIS and for some reason if I run a migration with some messed up code It throws an error such as
ValueError: invalid literal for int() with base 10: 'foo'
Of course it throws an error my code was bad! But then I return the code to what I know is and once was a functioning working state then run:
python manage.py makemigrations bar
That runs fine. Then I run..
python manage.py migrate
And I get the same error that I got before when I know I removed issue.
There is nothing complicated going on with my code I just started the project and the only things I added where what was required in the GeoDjango tutorial then I added my own models. Is their any Django, PostGIS, or Postgres settings that could be causing the database to retain its errors after a migration? Because the only thing that has worked for me so far is deleting the database and making a new one. This has never happened too me on a regular Postgres/Django project so I feel it may be related to PostGIS or GeoDjango