migrate command returns the message "ValueError: Cannot use object with type int for a spatial lookup parameter."

152 views
Skip to first unread message

Majid Houtach

unread,
Oct 23, 2018, 2:36:36 AM10/23/18
to geodjango
Hello,

I have installed geodjango thanks to homebrew :
pip3 install psycopg2
brew install postgresql
brew install postgis
brew install gdal
brew install libgeoip
pip3 install proj
then I modified the settings.py :
DATABASES = {
    'default': {
        'ENGINE': 'django.contrib.gis.db.backends.postgis',
        'NAME': 'evenDatabase',
        'USER': 'superadm',
        'PASSWORD': '',
        'HOST': '',
        'PORT': '5432',
    },
}
and added 'django.contrib.gis' to the key NSTALLED_APPS.
I use Django 2 on macOS 10.1.2
but when I run the migrate command, i have the following messages :

Mac-mini-de-****:even ******$ python3.7 manage.py makemigrations

/Library/Frameworks/Python.framework/Versions/3.7/lib/python3.7/site-packages/psycopg2/__init__.py:144: UserWarning: The psycopg2 wheel package will be renamed from release 2.8; in order to keep installing from binary please use "pip install psycopg2-binary" instead. For details see: <http://initd.org/psycopg/docs/install.html#binary-install-from-pypi>.

  """)

No changes detected

Mac-mini-de-****:even ******$ python3.7 manage.py migrate

/Library/Frameworks/Python.framework/Versions/3.7/lib/python3.7/site-packages/psycopg2/__init__.py:144: UserWarning: The psycopg2 wheel package will be renamed from release 2.8; in order to keep installing from binary please use "pip install psycopg2-binary" instead. For details see: <http://initd.org/psycopg/docs/install.html#binary-install-from-pypi>.

  """)

Operations to perform:

  Apply all migrations: admin, administration, auth, contenttypes, sessions

Running migrations:

  Applying administration.0010_auto_20181020_2155...Traceback (most recent call last):

  File "manage.py", line 15, in <module>

    execute_from_command_line(sys.argv)

  File "/Library/Frameworks/Python.framework/Versions/3.7/lib/python3.7/site-packages/django/core/management/__init__.py", line 371, in execute_from_command_line

    utility.execute()

  File "/Library/Frameworks/Python.framework/Versions/3.7/lib/python3.7/site-packages/django/core/management/__init__.py", line 365, in execute

    self.fetch_command(subcommand).run_from_argv(self.argv)

  File "/Library/Frameworks/Python.framework/Versions/3.7/lib/python3.7/site-packages/django/core/management/base.py", line 288, in run_from_argv

    self.execute(*args, **cmd_options)

  File "/Library/Frameworks/Python.framework/Versions/3.7/lib/python3.7/site-packages/django/core/management/base.py", line 335, in execute

    output = self.handle(*args, **options)

  File "/Library/Frameworks/Python.framework/Versions/3.7/lib/python3.7/site-packages/django/core/management/commands/migrate.py", line 200, in handle

    fake_initial=fake_initial,

  File "/Library/Frameworks/Python.framework/Versions/3.7/lib/python3.7/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 "/Library/Frameworks/Python.framework/Versions/3.7/lib/python3.7/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 "/Library/Frameworks/Python.framework/Versions/3.7/lib/python3.7/site-packages/django/db/migrations/executor.py", line 244, in apply_migration

    state = migration.apply(state, schema_editor)

  File "/Library/Frameworks/Python.framework/Versions/3.7/lib/python3.7/site-packages/django/db/migrations/migration.py", line 122, in apply

    operation.database_forwards(self.app_label, schema_editor, old_state, project_state)

  File "/Library/Frameworks/Python.framework/Versions/3.7/lib/python3.7/site-packages/django/db/migrations/operations/fields.py", line 84, in database_forwards

    field,

  File "/Library/Frameworks/Python.framework/Versions/3.7/lib/python3.7/site-packages/django/db/backends/base/schema.py", line 423, in add_field

    definition, params = self.column_sql(model, field, include_default=True)

  File "/Library/Frameworks/Python.framework/Versions/3.7/lib/python3.7/site-packages/django/db/backends/base/schema.py", line 168, in column_sql

    default_value = self.effective_default(field)

  File "/Library/Frameworks/Python.framework/Versions/3.7/lib/python3.7/site-packages/django/db/backends/base/schema.py", line 240, in effective_default

    default = field.get_db_prep_save(default, self.connection)

  File "/Library/Frameworks/Python.framework/Versions/3.7/lib/python3.7/site-packages/django/db/models/fields/__init__.py", line 767, in get_db_prep_save

    return self.get_db_prep_value(value, connection=connection, prepared=False)

  File "/Library/Frameworks/Python.framework/Versions/3.7/lib/python3.7/site-packages/django/contrib/gis/db/models/fields.py", line 147, in get_db_prep_value

    super().get_db_prep_value(value, connection, *args, **kwargs),

  File "/Library/Frameworks/Python.framework/Versions/3.7/lib/python3.7/site-packages/django/db/models/fields/__init__.py", line 762, in get_db_prep_value

    value = self.get_prep_value(value)

  File "/Library/Frameworks/Python.framework/Versions/3.7/lib/python3.7/site-packages/django/contrib/gis/db/models/fields.py", line 190, in get_prep_value

    raise ValueError('Cannot use object with type %s for a spatial lookup parameter.' % type(obj).__name__)

ValueError: Cannot use object with type int for a spatial lookup parameter.



It should be great if someone have any idea of the possible cause of this problem.


Thank you for your attention.


Claude Paroz

unread,
Oct 23, 2018, 2:43:05 AM10/23/18
to geod...@googlegroups.com
Le 22.10.18 à 22:25, Majid Houtach a écrit :
...
> I use Django 2 on macOS 10.1.2
>
> but when I run the migrate command, i have the following messages :
...
>
> *Running migrations:*
>
>   Applying administration.0010_auto_20181020_2155...Traceback (most
> recent call last):
...
>   File
> "/Library/Frameworks/Python.framework/Versions/3.7/lib/python3.7/site-packages/django/contrib/gis/db/models/fields.py",
> line 190, in get_prep_value
>
>     raise ValueError('Cannot use object with type %s for a spatial
> lookup parameter.' % type(obj).__name__)
>
> ValueError: Cannot use object with type int for a spatial lookup parameter.
>
> It should be great if someone have any idea of the possible cause of
> this problem.

Hi Majid,

Looks like an issue with some default value not suitable for some field,
but it is not possible to help you without knowing the content of the
0010_auto_20181020_2155 migration.
Is the 'administration' app your own app or a 3rd party app?

Claude
--
www.2xlibre.net
Reply all
Reply to author
Forward
0 new messages