geodesign / django-raster

Django-raster allows you to create tiled map services (TMS) and raster map algebra end points for web maps. It is Python-based, and requires GeoDjango with a PostGIS backend.
BSD 3-Clause "New" or "Revised" License
96 stars 39 forks source link

Migrate error of installation #49

Closed JohnLyu94 closed 4 years ago

JohnLyu94 commented 4 years ago

Hi, I am new in webgis development. I am trying to load, display and show raster files using geodjango as the base framework. Thus, I am looking for the solution by using django-raster.

My env version info is like:

Python-3.6 Django-3.0.3 postgresql-9.5 postgresql-9.5-postgis-2.4 django-raster-0.8

I try to set django-raster as the installation shown, but I get an error when I migrate raster to database.

Operations to perform:
  Apply all migrations: admin, auth, contenttypes, raster, sessions, world
Running migrations:
  Applying raster.0002_auto_20140925_0723...Traceback (most recent call last):
  File "/home/johnlyu/anaconda3/envs/geodjango/lib/python3.6/site-packages/django/db/backends/utils.py", line 86, in _execute
    return self.cursor.execute(sql, params)
psycopg2.errors.UndefinedTable: relation "raster_rastertile" does not exist

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

Traceback (most recent call last):
  File "manage.py", line 21, in <module>
    main()
  File "manage.py", line 17, in main
    execute_from_command_line(sys.argv)
  File "/home/johnlyu/anaconda3/envs/geodjango/lib/python3.6/site-packages/django/core/management/__init__.py", line 401, in execute_from_command_line
    utility.execute()
  File "/home/johnlyu/anaconda3/envs/geodjango/lib/python3.6/site-packages/django/core/management/__init__.py", line 395, in execute
    self.fetch_command(subcommand).run_from_argv(self.argv)
  File "/home/johnlyu/anaconda3/envs/geodjango/lib/python3.6/site-packages/django/core/management/base.py", line 328, in run_from_argv
    self.execute(*args, **cmd_options)
  File "/home/johnlyu/anaconda3/envs/geodjango/lib/python3.6/site-packages/django/core/management/base.py", line 369, in execute
    output = self.handle(*args, **options)
  File "/home/johnlyu/anaconda3/envs/geodjango/lib/python3.6/site-packages/django/core/management/base.py", line 83, in wrapped
    res = handle_func(*args, **kwargs)
  File "/home/johnlyu/anaconda3/envs/geodjango/lib/python3.6/site-packages/django/core/management/commands/migrate.py", line 233, in handle
    fake_initial=fake_initial,
  File "/home/johnlyu/anaconda3/envs/geodjango/lib/python3.6/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/johnlyu/anaconda3/envs/geodjango/lib/python3.6/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/johnlyu/anaconda3/envs/geodjango/lib/python3.6/site-packages/django/db/migrations/executor.py", line 245, in apply_migration
    state = migration.apply(state, schema_editor)
  File "/home/johnlyu/anaconda3/envs/geodjango/lib/python3.6/site-packages/django/db/migrations/migration.py", line 124, in apply
    operation.database_forwards(self.app_label, schema_editor, old_state, project_state)
  File "/home/johnlyu/anaconda3/envs/geodjango/lib/python3.6/site-packages/django/db/migrations/operations/fields.py", line 249, in database_forwards
    schema_editor.alter_field(from_model, from_field, to_field)
  File "/home/johnlyu/anaconda3/envs/geodjango/lib/python3.6/site-packages/django/db/backends/base/schema.py", line 565, in alter_field
    old_db_params, new_db_params, strict)
  File "/home/johnlyu/anaconda3/envs/geodjango/lib/python3.6/site-packages/django/db/backends/postgresql/schema.py", line 154, in _alter_field
    new_db_params, strict,
  File "/home/johnlyu/anaconda3/envs/geodjango/lib/python3.6/site-packages/django/db/backends/base/schema.py", line 756, in _alter_field
    self.execute(self._create_index_sql(model, [new_field]))
  File "/home/johnlyu/anaconda3/envs/geodjango/lib/python3.6/site-packages/django/db/backends/base/schema.py", line 142, in execute
    cursor.execute(sql, params)
  File "/home/johnlyu/anaconda3/envs/geodjango/lib/python3.6/site-packages/django/db/backends/utils.py", line 100, in execute
    return super().execute(sql, params)
  File "/home/johnlyu/anaconda3/envs/geodjango/lib/python3.6/site-packages/django/db/backends/utils.py", line 68, in execute
    return self._execute_with_wrappers(sql, params, many=False, executor=self._execute)
  File "/home/johnlyu/anaconda3/envs/geodjango/lib/python3.6/site-packages/django/db/backends/utils.py", line 77, in _execute_with_wrappers
    return executor(sql, params, many, context)
  File "/home/johnlyu/anaconda3/envs/geodjango/lib/python3.6/site-packages/django/db/backends/utils.py", line 86, in _execute
    return self.cursor.execute(sql, params)
  File "/home/johnlyu/anaconda3/envs/geodjango/lib/python3.6/site-packages/django/db/utils.py", line 90, in __exit__
    raise dj_exc_value.with_traceback(traceback) from exc_value
  File "/home/johnlyu/anaconda3/envs/geodjango/lib/python3.6/site-packages/django/db/backends/utils.py", line 86, in _execute
    return self.cursor.execute(sql, params)
django.db.utils.ProgrammingError: relation "raster_rastertile" does not exist

Could you please help me?

yellowcap commented 4 years ago

This looks like your migration command starts with the second migration 0002_auto_2014092..., where the first migration sets up the raster_rastertile table. This means that maybe your DB is out of sync with the migration. I.e. Django thinks the first migration was already applied, but it is not. This is just a guess.

Can you try to use a new clean database to setup your project with django-raster?

JohnLyu94 commented 4 years ago

This looks like your migration command starts with the second migration 0002_auto_2014092..., where the first migration sets up the raster_rastertile table. This means that maybe your DB is out of sync with the migration. I.e. Django thinks the first migration was already applied, but it is not. This is just a guess.

Can you try to use a new clean database to setup your project with django-raster?

Thank you for your reply. It works. I recreate a database and a new project of django. It seems like that I defined a raster model before using django-raster. Thank you very much!