By Jack Morgan
Kia ora!
I’ve been unable to run Django migrations on an App Platform dev database, as it throws the error permission denied for schema public.
I’ve looked at the following posts, but still no luck.
When connecting to the deployed Django resource and running python manage.py migrate in the console, or creating a job instance to run the same command, I get the following errors:
Sep 04 05:02:42
Operations to perform:
Sep 04 05:02:42
Apply all migrations: account, admin, auth, contenttypes, mfa, sessions, sites, socialaccount, users
Sep 04 05:02:42
Running migrations:
Sep 04 05:02:42
Traceback (most recent call last):
Sep 04 05:02:42
File "/usr/local/lib/python3.12/site-packages/django/db/backends/utils.py", line 103, in _execute
Sep 04 05:02:42
return self.cursor.execute(sql)
Sep 04 05:02:42
^^^^^^^^^^^^^^^^^^^^^^^^
Sep 04 05:02:42
File "/usr/local/lib/python3.12/site-packages/psycopg/cursor.py", line 97, in execute
Sep 04 05:02:42
raise ex.with_traceback(None)
Sep 04 05:02:42
psycopg.errors.InsufficientPrivilege: permission denied for schema public
Sep 04 05:02:42
LINE 1: CREATE TABLE "django_migrations" ("id" bigint NOT NULL PRIMA...
Sep 04 05:02:42
^
Sep 04 05:02:42
Sep 04 05:02:42
The above exception was the direct cause of the following exception:
Sep 04 05:02:42
Sep 04 05:02:42
Traceback (most recent call last):
Sep 04 05:02:42
File "/usr/local/lib/python3.12/site-packages/django/db/migrations/recorder.py", line 78, in ensure_schema
Sep 04 05:02:42
editor.create_model(self.Migration)
Sep 04 05:02:42
File "/usr/local/lib/python3.12/site-packages/django/db/backends/base/schema.py", line 512, in create_model
Sep 04 05:02:42
self.execute(sql, params or None)
Sep 04 05:02:42
File "/usr/local/lib/python3.12/site-packages/django/db/backends/postgresql/schema.py", line 45, in execute
Sep 04 05:02:42
return super().execute(sql, params)
Sep 04 05:02:42
^^^^^^^^^^^^^^^^^^^^^^^^^^^^
Sep 04 05:02:42
File "/usr/local/lib/python3.12/site-packages/django/db/backends/base/schema.py", line 204, in execute
Sep 04 05:02:42
cursor.execute(sql, params)
Sep 04 05:02:42
File "/usr/local/lib/python3.12/site-packages/sentry_sdk/utils.py", line 1816, in runner
Sep 04 05:02:42
return sentry_patched_function(*args, **kwargs)
Sep 04 05:02:42
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
Sep 04 05:02:42
File "/usr/local/lib/python3.12/site-packages/sentry_sdk/integrations/django/__init__.py", line 652, in execute
From my understanding and local testing, Django should only modify the public schema in the db database. Anything I’ve missed?
This textbox defaults to using Markdown to format your answer.
You can type !ref in this text area to quickly search our full set of tutorials, documentation & marketplace offerings and insert the link!
Accepted Answer
Hi there,
I think that you should not be using the db database, instead you should just use the default postgres database itself that the database user has access to.
How are you defining your database details exactly?
Let me know how it goes.
To run Django migrations on your App Platform development database, follow these steps:
Set up your environment variables: Make sure your Django app on App Platform is configured with the correct environment variables pointing to your development database (e.g.,
Connect to your app’s container or use remote execution: Since App Platform runs your app in a managed environment, you generally need to run migrations inside the deployed container or via the platform’s CLI.
Run migrations with a deployment hook or manually:
python manage py migrate
Deployment hook: Configure a post-deploy hook in your App Platform service to run migrations automatically after each deployment. For example, add this command in your App Platform dashboard:
python manage py migrate --noinput
Ensure the dev database is accessible: The dev database should allow connections from your App Platform environment. Confirm network rules and credentials are set correctly.
Check logs for migration output: Review the App Platform logs to verify that migrations ran successfully without errors.
Example post-deploy hook snippet:
python manage py migrate --noinput
This approach ensures your migrations are always applied in your dev environment automatically after deployment.
Get paid to write technical tutorials and select a tech-focused charity to receive a matching donation.
Full documentation for every DigitalOcean product.
The Wave has everything you need to know about building a business, from raising funding to marketing your product.
Stay up to date by signing up for DigitalOcean’s Infrastructure as a Newsletter.
New accounts only. By submitting your email you agree to our Privacy Policy
Scale up as you grow — whether you're running one virtual machine or ten thousand.
Sign up and get $200 in credit for your first 60 days with DigitalOcean.*
*This promotional offer applies to new accounts only.