Ticket #168 (closed defect: fixed)
South fails to add a blank=True/null=False field without manually adding default value
| Reported by: | Erik Allik | Owned by: | andrew |
|---|---|---|---|
| Priority: | minor | Milestone: | 0.7 |
| Component: | commands | Version: | 0.6-pre |
| Keywords: | commands migrate | Cc: |
Description
For example, adding:
my_field = models.CharField(max_length=255, blank=True)
should assume a default value of "", but currently running
db.add_column('myapp_mymodel', 'my_field', models.CharField(max_length=255, blank=True))
gives
psycopg2.IntegrityError: column "my_field" contains null values
...at least on PostgreSQL 8.3, that is.
Not a blocker, but annoyance nevertheless. Using SVN r258.
Attachments
Change History
comment:3 Changed 2 years ago by mbarto
- Cc mbarto added
- Status changed from assigned to closed
- Resolution set to fixed
If the field allows empty strings (which CharFields? do) we will manually add the default as empty string "", and at the same time throw ValueError? to avoid this behavior for fields without the ability to allow empty strings (ie. IntegerFields?).
comment:4 Changed 2 years ago by smcoll
i got this same error with a TextField?(blank=True) using 0.6.2. Shouldn't a TextField? have the same behavior as a CharField??
comment:5 Changed 2 years ago by andrew
It probably should do, yes; I'm not sure why it isn't. Could you open a new ticket for this, with information about what database and Django you're using?
comment:6 Changed 2 years ago by anonymous
I don't think this is minor. Adding a blank CharField? or TextField? is one of the simplest, most common use cases, and often the first thing you try with South. This bug--which is in the current stable version--means South throws an exception and fails in that extemely common case.
comment:7 Changed 2 years ago by andrew
This issue is fixed in the upcoming development release of South, so there's no need to re-open it.
Also, for the record, many people do add CharFields? and TextFields? all the time, and they work (the issue in 0.6.2 only affects certain combinations of DBMSen and field options, and as I said, is now fixed in trunk).

Not a blocker, but indeed annoying - still, somewhat matches my expectations. Bumping to 0.7.