Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

how can I use PostgreSQL's "text" column type in Django?

Can I have in Django's model a column of PostgreSQL's "text" type? If so, how can I do that?

like image 787
user983447 Avatar asked Mar 22 '23 08:03

user983447


1 Answers

You can use the TextField

A large text field. The default form widget for this field is a Textarea.

Usage:

class MyModel(models.Model):
    text_field = models.TextField("My field label", null=True, blank=True)

If the text is not too long, You could also consider CharField

A string field, for small- to large-sized strings. For large amounts of text, use TextField.

The default form widget for this field is a TextInput.

Usage:

class MyModel(models.Model):
    text_field = models.CharField("My field label", max_length=1024, null=True, blank=True)
like image 107
karthikr Avatar answered Apr 02 '23 09:04

karthikr