On Wed, 2006-07-19 at 21:25 -0400, Joe wrote:
> Hi,
> 
> I ran manage.py inspectdb on an existing PostgreSQL database and have
> some questions on the results.
> 
> Three of the tables use the tsearch2 module which defines a 'tsvector'
> data type (to create a searchable text index).  Currently, the PHP app
> is unaware of the existence of these columns, except in a single module
> that implements the search capability.  inspectdb mapped the tsvector
> type to a Django TextField.  My question:  is it necessary to specify
> this column/field as part of the Django model, considering that it will
> be used only in a couple of internal SQL queries?

I could have sworn I answered this just yesterday on this list:
http://groups.google.com/group/django-users/browse_frm/thread/a13b9b12488569ef/549fa8112c0c97a7#549fa8112c0c97a7

Short answer: "no problems".

> 
> The database uses the CHAR(n) (or CHARACTER(n)) datatype in several
> places, i.e., a fixed length character type, typically for very short
> "code" type columns.  inspectdb also mapped those to TextFields
> indicating it was a guess.  Can I remap them to CharField(maxlength=n)
> or will that have unintended side-effects (and why is inspectdb unaware
> of CHAR types?).

The important characterstic of CHAR that you forgot to mention was that
it is blank padded on the right, so that it's length is always "n".
CharField maps to a VARCHAR (not blank padded). There is no equivalent
to blank-padded fields in Django. Up to you how you wish to resolve that
one.

> One of those CHAR(n) types used to be a MySQL date type, but we had to
> convert to CHAR(10) (i.e., YYYY-MM-DD) because some dates accepted by
> MySQL were invalid as far as PgSQL was concerned.  The column is used
> for a "publication date".  Such a date has full day, month, year when it
> refers to a daily publication like a newspaper or online article, but it
> may have only month and year for a monthly magazine or just a year for a
> book.  MySQL allows zeros for the missing elements, but PgSQL said those
> were invalid dates.  I'd like to know if the Django DateField conforms
> to PgSQL or MySQL in this respect and whether it could be used for these
> publication dates.

Some of this stuff is pretty easy to test, btw. Just set up a small
model and experiment. You'll get a better feel for things that just
asking somebody else. :-)

Django's date fields have to valid Python datetime.date types for a
start, so missing months and days are not going to work. Those types are
then converted to strings (YYYY-MM-DD, typically) for insertion into the
database. So, in short, you're not going to be able to have 0's in those
places.

> I notice that Django has a URLField.  Our database has several 'url'
> columns, but most of them have been entered without the
> 'http://' (unless the URL is for an https) since the app provides that
> default where necessary.  Is URLField compatible with that behavior?

The validator on URL input fields requires that it matches the regular
expression r'^https?://\S+$'. So, yes, "http(s)" is required. If you
don't want that, just use a CharField (you can even write your own
validator for the field if you want it to match some particular format).

Best wishes,
Malcolm


--~--~---------~--~----~------------~-------~--~----~
You received this message because you are subscribed to the Google Groups 
"Django users" group.
To post to this group, send email to django-users@googlegroups.com
To unsubscribe from this group, send email to [EMAIL PROTECTED]
For more options, visit this group at 
http://groups.google.com/group/django-users
-~----------~----~----~----~------~----~------~--~---

Reply via email to