4

I have no valuable data in my database and was unable to migrate, as you can see here:

ResetDjango postgresql database? flush does not work

I tried to reset the database using:

  1. Delete migration files
  2. Enter psql command prompt. Connect to database. drop schema public cascade; create schema public;
  3. Step 2 unfortunately seemed to have removed my user role and rights so I went back to the psql command promt and recreated those.

Now I have tried to migrate again, and it still doesn't work. What might be wrong now?

vagrant@vagrant-ubuntu-trusty-64:/vagrant/grader$ python3 manage.py makemigrations Migrations for 'core': 0001_initial.py: - Create model Student vagrant@vagrant-ubuntu-trusty-64:/vagrant/grader$ python3 manage.py migrate Traceback (most recent call last): File "/usr/local/lib/python3.4/dist-packages/django/db/backends/utils.py", line 62, in execute return self.cursor.execute(sql) psycopg2.ProgrammingError: no schema has been selected to create in The above exception was the direct cause of the following exception: Traceback (most recent call last): File "/usr/local/lib/python3.4/dist-packages/django/db/migrations/recorder.py", line 57, in ensure_schema editor.create_model(self.Migration) File "/usr/local/lib/python3.4/dist-packages/django/db/backends/base/schema.py", line 284, in create_model self.execute(sql, params or None) File "/usr/local/lib/python3.4/dist-packages/django/db/backends/base/schema.py", line 110, in execute cursor.execute(sql, params) File "/usr/local/lib/python3.4/dist-packages/django/db/backends/utils.py", line 79, in execute return super(CursorDebugWrapper, self).execute(sql, params) File "/usr/local/lib/python3.4/dist-packages/django/db/backends/utils.py", line 64, in execute return self.cursor.execute(sql, params) File "/usr/local/lib/python3.4/dist-packages/django/db/utils.py", line 95, in __exit__ six.reraise(dj_exc_type, dj_exc_value, traceback) File "/usr/local/lib/python3.4/dist-packages/django/utils/six.py", line 685, in reraise raise value.with_traceback(tb) File "/usr/local/lib/python3.4/dist-packages/django/db/backends/utils.py", line 62, in execute return self.cursor.execute(sql) django.db.utils.ProgrammingError: no schema has been selected to create in During handling of the above exception, another exception occurred: Traceback (most recent call last): File "manage.py", line 10, in <module> execute_from_command_line(sys.argv) File "/usr/local/lib/python3.4/dist-packages/django/core/management/__init__.py", line 350, in execute_from_command_line utility.execute() File "/usr/local/lib/python3.4/dist-packages/django/core/management/__init__.py", line 342, in execute self.fetch_command(subcommand).run_from_argv(self.argv) File "/usr/local/lib/python3.4/dist-packages/django/core/management/base.py", line 348, in run_from_argv self.execute(*args, **cmd_options) File "/usr/local/lib/python3.4/dist-packages/django/core/management/base.py", line 399, in execute output = self.handle(*args, **options) File "/usr/local/lib/python3.4/dist-packages/django/core/management/commands/migrate.py", line 89, in handle executor = MigrationExecutor(connection, self.migration_progress_callback) File "/usr/local/lib/python3.4/dist-packages/django/db/migrations/executor.py", line 20, in __init__ self.loader = MigrationLoader(self.connection) File "/usr/local/lib/python3.4/dist-packages/django/db/migrations/loader.py", line 49, in __init__ self.build_graph() File "/usr/local/lib/python3.4/dist-packages/django/db/migrations/loader.py", line 176, in build_graph self.applied_migrations = recorder.applied_migrations() File "/usr/local/lib/python3.4/dist-packages/django/db/migrations/recorder.py", line 65, in applied_migrations self.ensure_schema() File "/usr/local/lib/python3.4/dist-packages/django/db/migrations/recorder.py", line 59, in ensure_schema raise MigrationSchemaMissing("Unable to create the django_migrations table (%s)" % exc) django.db.migrations.exceptions.MigrationSchemaMissing: Unable to create the django_migrations table (no schema has been selected to create in ) 
8
  • you tried migrate single app? like python manage.py migrate "your_app" ? Commented Jan 3, 2016 at 11:04
  • I had not tried it before you suggested it. But I tried it just now and I get the same error output. My project only has one app so far. Commented Jan 3, 2016 at 11:05
  • 3
    have a look at this question dba.stackexchange.com/questions/106057/… Commented Jan 3, 2016 at 11:08
  • so, if you create new db, maybe you change something in db settings? like user and db name. You need change it in settings too Commented Jan 3, 2016 at 11:09
  • 1
    @mic4ael: grant usage on schema public to public; grant create on schema public to public; solved the problem Commented Jan 3, 2016 at 11:20

2 Answers 2

2

Adding these two lines in settings.py at the top are important for mysql to connect:

from django.db.backends.mysql.base import DatabaseWrapper DatabaseWrapper.data_types['DateTimeField']='datetime' 
Sign up to request clarification or add additional context in comments.

Comments

0

it is simple, it is related with permission and i have fixed simply: go to your postgres(am using arch linux btw):

sudo -i -u postgres 

then,

psql 

then run:

GRANT ALL PRIVILEGES ON SCHEMA public TO your_django_user 

and it shows output: enter image description here

and also finally run:

ALTER ROLE your_django_user WITH SUPERUSER 

I HOPE NOW python manage.py migrate will work fine.

Comments

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.