0

I have a Django app running on AWS elastic beanstalk. It was previously connected to a MySQL RDS instance. I have been through several steps to migrate the data from a MySQL instance to a PostgreSQL instance. In brief I connected to the postgres instance and ran python manage.py migrate

I then ran python manage.py sqlflush and ran the resulting SQL commands

Then I imported a json fixture of content types from the MySQL db. I created the fixture (when connected to the MySQL db) with python manage.py dumpdata contenttypes --indent=4 --natural-foreign > contenttype.json and imported it into the PostgreSQL db with python manage.py loaddata contenttype.json

The above preserves PKs and FKs

I then used AWS DMS to load the data from the MySQL instance to the PostgreSQL instance.

Using the Django app (e.g. through Django admin) all the data can be read from the Postgres instance. However, trying to post data to the database results in a 500 error.

Could this be a problem with security settings in AWS? It seems odd that I can read data from the DB but not post to it.

I've tried connecting to the DB using pgAdmin 4 with the same connection settings. I was able to use an INSERT statement to post to the database from there (but had to explicitly state the PK value)

Update

As suggested by Mark B the problem was Primary Keys. Many of the sequences in postgres had been reset to 1 as the current value. Finding the max value of the ID (PK) in each table and updating the corresponding sequence has got everything working. This question on sequences and primary keys was useful.

5
  • "Could this be a problem with security settings in AWS?" No, absolutely not. There's something going on with your database user account. Commented Jan 6, 2023 at 16:07
  • Does database user account mean IAM policies? Commented Jan 6, 2023 at 16:22
  • No it means the account you enter in when you are connecting via pgAdmin. The account you use in the database connection settings in Django. The account that exists inside the PostgreSQL database server. Commented Jan 6, 2023 at 16:41
  • Looking at your question again, it seems you got a 500 error and didn't look further. 500 just means there was an error on the server and you need to look at the server logs to see what the actual error is. It could be that you are violating some sort of foreign key constraint or something in the database insert. You need to go to the Django logs to find the actual error message to see what you need to fix. Commented Jan 6, 2023 at 16:43
  • You are correct @MarkB it's a primary key constraint error. It seems all the pks have reset to 1 in the Django app. This might require a new question. Commented Jan 6, 2023 at 16:47

0

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.