how does django model after text[] in postgresql [duplicate]
Possible Duplicate:
How to map PostgreSQL array field in Django ORM
I have a table wit one of the columns of datatype text[] in postgresql. May I know how do I access this column using django models orm? I'm aware that theres a commaseparatedintegerfield, but no such for text related fields. Do i use textfield or need to create a custom field for this?
I don't think Django ORM supports PostgreSQL arrays. It's unsurprising, as this looks like a fairly PostgreSQL-specific feature. If you really have to use arrays, your best bet is to construct SQL queries as text by hand. Otherwise, just turn the array columns into tables, as Mark suggests; that is by far a more portable and conceptually clean solution (although the performance may be lower).
There are often times when the PostgreSQL array field is the right solution. For instance, when working with a legacy database. The django-dbarray project on github adds support for this. I haven't used it, but it looks like usage is basically:
from django.db import model
import dbarray
class Person(models.Model):
birthdate = models.DateField()
nicknames = dbarray.TextArrayField()
精彩评论