Forums

Cant migrate django database on pythonanywhere

I have django project at https://gitlab.com/kurisu170/api,, which is basically rest api that allows me to register, login and retrieve my information with jwt tokens. When i try to execute ./manage.py migrate on pythonanywhere i get following error https://pastebin.com/rEbTFe2E,

Is there any limitations on pythonanywhere that i am not aware of that don't let me migrate my database or i somehow misconfigured my project that i can only migrate my database on my local machine? I dont use mysql or postgres so i dont think there should be any issues with database access.

Steps to reproduce:

Inside bash console

virtualenv --python=/usr/bin/python3.8 django-env
cd django-env
source bin/activate 
git clone https://gitlab.com/kurisu170/api.git roctik_api
cd roctik_api
pip install -r requirements.txt

Then i follow tutorial at https://help.pythonanywhere.com/pages/DeployExistingDjangoProject/ and set variables to following values

Virtualenv: /home/kurisu171/django-env

Source code/Working directory: /home/kurisu171/django-env/roctik_api

And inside wsgi file

path='/home/kurisu171/django-env/roctik_api'
os.environ['DJANGO_SETTINGS_MODULE'] = 'roctik_api.settings'

Then in bash console i run

./manage.py migrate

And it produces an error.

How can i fix it? The error points to some django package that i don't know how work. On my local Arch machine and CentOS inside a virtualbox it works without any problem

Just tried doing the same thing on heroku to test if it is pythonanywhere-specific error, got the same error there too, probably there is some problem in code, but i don't know how to find it and where to even look for it

What error message are you getting?

(django-env) 10:39 ~/django-env/roctik_api (master)$ ./manage.py migrate Operations to perform: Apply all migrations: admin, auth, contenttypes, sessions Running migrations: Applying contenttypes.0001_initial... OK Applying admin.0001_initial...Traceback (most recent call last): File "/home/kurisu171/django-env/lib/python3.8/site-packages/django/db/backends/utils.py", line 82, in _execute return self.cursor.execute(sql) File "/home/kurisu171/django-env/lib/python3.8/site-packages/django/db/backends/sqlite3/base.py", line 411, in execute return Database.Cursor.execute(self, query) sqlite3.OperationalError: no such table: api_user

The above exception was the direct cause of the following exception:

Traceback (most recent call last):
  File "./manage.py", line 22, in <module>
    main()
  File "./manage.py", line 18, in main
    execute_from_command_line(sys.argv)
  File "/home/kurisu171/django-env/lib/python3.8/site-packages/django/core/management/__init__.py", line 401, in execute_from_command_line
    utility.execute()
  File "/home/kurisu171/django-env/lib/python3.8/site-packages/django/core/management/__init__.py", line 395, in execute
    self.fetch_command(subcommand).run_from_argv(self.argv)
  File "/home/kurisu171/django-env/lib/python3.8/site-packages/django/core/management/base.py", line 330, in run_from_argv
    self.execute(*args, **cmd_options)
  File "/home/kurisu171/django-env/lib/python3.8/site-packages/django/core/management/base.py", line 371, in execute
    output = self.handle(*args, **options)
  File "/home/kurisu171/django-env/lib/python3.8/site-packages/django/core/management/base.py", line 85, in wrapped
    res = handle_func(*args, **kwargs)
  File "/home/kurisu171/django-env/lib/python3.8/site-packages/django/core/management/commands/migrate.py", line 243, in handle
    post_migrate_state = executor.migrate(
  File "/home/kurisu171/django-env/lib/python3.8/site-packages/django/db/migrations/executor.py", line 117, in migrate
    state = self._migrate_all_forwards(state, plan, full_plan, fake=fake, fake_initial=fake_initial)
  File "/home/kurisu171/django-env/lib/python3.8/site-packages/django/db/migrations/executor.py", line 147, in _migrate_all_forwards
    state = self.apply_migration(state, migration, fake=fake, fake_initial=fake_initial)
  File "/home/kurisu171/django-env/lib/python3.8/site-packages/django/db/migrations/executor.py", line 229, in apply_migration
    migration_recorded = True
  File "/home/kurisu171/django-env/lib/python3.8/site-packages/django/db/backends/sqlite3/schema.py", line 35, in __exit__
    self.connection.check_constraints()
  File "/home/kurisu171/django-env/lib/python3.8/site-packages/django/db/backends/sqlite3/base.py", line 361, in check_constraints
    cursor.execute(
  File "/home/kurisu171/django-env/lib/python3.8/site-packages/django/db/backends/utils.py", line 98, in execute
    return super().execute(sql, params)
  File "/home/kurisu171/django-env/lib/python3.8/site-packages/django/db/backends/utils.py", line 66, in execute
    return self._execute_with_wrappers(sql, params, many=False, executor=self._execute)
  File "/home/kurisu171/django-env/lib/python3.8/site-packages/django/db/backends/utils.py", line 75, in _execute_with_wrappers
    return executor(sql, params, many, context)
  File "/home/kurisu171/django-env/lib/python3.8/site-packages/django/db/backends/utils.py", line 84, in _execute
    return self.cursor.execute(sql, params)
  File "/home/kurisu171/django-env/lib/python3.8/site-packages/django/db/utils.py", line 90, in __exit__
    raise dj_exc_value.with_traceback(traceback) from exc_value
  File "/home/kurisu171/django-env/lib/python3.8/site-packages/django/db/backends/utils.py", line 82, in _execute
    return self.cursor.execute(sql)
  File "/home/kurisu171/django-env/lib/python3.8/site-packages/django/db/backends/sqlite3/base.py", line 411, in execute
    return Database.Cursor.execute(self, query)
django.db.utils.OperationalError: no such table: api_user

That looks like you have something in your admin that needs a model that you have not included. Perhaps you can try starting by migrating just the django app that has the model for that table.

Entered

./manage.py makemigrations api
./manage.py migrate api
./manage.py migrate

And it worked, thank you. But i wonder, why on remote server i need to first migrate model when on on local machine i can just run migrate and it will not produce any errors?

You probably ran the admin migrations before introducing the api app and then you introduced a dependency between admin and api later.