liuyang1520 / django-command-extensions

Automatically exported from code.google.com/p/django-command-extensions
MIT License
0 stars 0 forks source link

key error in data_types_reverse when running sqldiff command #95

Open GoogleCodeExporter opened 8 years ago

GoogleCodeExporter commented 8 years ago
What steps will reproduce the problem?
1. python manage.py sqldiff [appname]

What is the expected output? What do you see instead?

I expect to see a list of differences between the model and the database,
however for two of my appnames i get an error like this

  File "/path/to/django_extensions/management/commands/sqldiff.py", line
112, in handle_diff
    db_field_reverse_type = introspection_module.data_types_reverse[row[1]]
KeyError: 17506

or 

KeyError: 1042

What version of the product are you using? On what operating system?

I am using django revision 9498 (version 1.0.2) and django command
extensions revision 195. I am using a postgresql database backend (8.2.4)
with postgis installed, on python 2.4.2 

Please provide any additional information below.

This error is probably related to one of the column types in my model, but
i don't know which. The sqldiff command does work against some of my apps,
but not others so i know it's completely broken.

I will try to narrow this down further and post an update, but wanted to
get it documented here

Original issue reported on code.google.com by jehiah on 15 Apr 2009 at 1:26

GoogleCodeExporter commented 8 years ago
1042 is a bpchar (blank-padded-char)
http://www.postgresql.org/docs/8.0/static/typeconv-query.html

17506 is not a native postgresql data type that i can find. Did you create your 
own
custom data types ?

Created django ticket for the inclusion of 1042 and 20 (bpchar and int8) into
data_types_reverse: http://code.djangoproject.com/ticket/10837

Also added a patch to sqldiff to check datatypes and report when an unknown 
datatype
is found.

Only question remaining is should sqldiff also inform about the difference 
between a
'varchar' as suggested by Django for a field and 'char'. Personally I think 
this is
not necessary as the model should work perfectly fine no matter if it's a char 
or
varchar.

These changes are in the new master repository at github.
Please get the latest version from there.

Original comment by v.oostv...@gmail.com on 16 Apr 2009 at 9:46

GoogleCodeExporter commented 8 years ago
17506 is a django.contrib.gis.db.models.fields.PointField type, which in 
postgresql
shows as a type of 'geometry'.

Original comment by jehiah on 16 Apr 2009 at 3:07

GoogleCodeExporter commented 8 years ago
oops I forgot to add that the latest version from github works for type 1042

I get the following error for type 17506 as db_type is None, and i'd be happy to
patch, but i don't see an example of raising errors for sqldiff

File
"/home/jczebota/adc/djangoapps/django_extensions/management/commands/sqldiff.py"
,
line 491, in get_field_db_type
    db_type += ' '+check_constraint
TypeError: unsupported operand type(s) for +=: 'NoneType' and 'unicode'

I've commited a fix here
http://github.com/jehiah/django-extensions/commit/407bdf8b8e8022fe9d798dce5a44a6
16208f96eb

which then gives me this output
-- Comment: Unknown database type for field 'the_geom' (17506)

Original comment by jehiah on 16 Apr 2009 at 3:38

GoogleCodeExporter commented 8 years ago
Thanks for the info and patch !

I was afraid something like that exception might happen as most of the code does
expect the result of get_field_db_type to be a string. Also I'm not very happy 
with
the addition of 'unknown_db_fields' to make sure sqldiff does not comment on 
the same
unknown database type multiple times. (but that is for another time to resolve 
:)

The comment about unknown database type's was at the moment the best i could 
think of
to handle types which are not specified by Django or sqldiff. If the message is 
not
clear enough I welcome suggestions.

It would be nice to handle gis types in sqldiff but I have no experience with 
gis.
I've started a branch called sqldiff-gis-types at
http://github.com/trbs/django-extensions/tree/sqldiff-gis-types

But after starting to look gis I think this might be a bit harder then a few 
simple
patches. 

(1) All db_types() for gis fields are None and they are all called 'geometry' in
postgresql so we need a different way of tracking the difference between 
different
type of geometry fields.

(2) Need to check for gis indexes manually (currently the standard output of 
sqldiff
will think they are indexes that are not defined by the model, thus needing to 
be
removed from the database, this is BAD!)

Sorry for the incoherent comment, if you would like to help getting sqldiff to
support gis (or in any case handle it gracefully even if it's not support) it 
would
be much appreciated.

Original comment by v.oostv...@gmail.com on 16 Apr 2009 at 4:55

GoogleCodeExporter commented 8 years ago

Original comment by v.oostv...@gmail.com on 16 Apr 2009 at 5:14