google-code-export / django-pyodbc

Automatically exported from code.google.com/p/django-pyodbc
BSD 3-Clause "New" or "Revised" License
0 stars 0 forks source link

Uses an empty String instead of Null on an object that is null #67

Closed GoogleCodeExporter closed 9 years ago

GoogleCodeExporter commented 9 years ago
Hello,

By default, Django uses all columns as NOT NULL, and using the interactive 
shell, I do the following:

e = Event(type='TYPEA')
e.save() 
e.source
''

Notice, it returns an empty String, while it should return an error saying 
cannot store null (since I didn't specify null). I am using Django 1.1.1 
and django-pyodbc r173

Database Table:

CREATE TABLE event (
  id INTEGER IDENTITY(0, 1) NOT NULL,
  type VARCHAR(512) NOT NULL,
  source VARCHAR(50) NOT NULL,
  creation DATETIME DEFAULT getdate() NOT NULL,
  PRIMARY KEY (id)
)

Django Model:

class Event(models.Model):
  type = models.CharField(max_length=512)
  source = models.CharField(max_length=50)
  creation = models.DateTimeField('date published', auto_now=True)

  def __unicode__(self):
    return self.type

  class Meta:
    db_table = 'event'

Original issue reported on code.google.com by m0.inter...@gmail.com on 6 Jan 2010 at 5:47

GoogleCodeExporter commented 9 years ago
need set null=True to field. example:
source = models.CharField(max_length=50, null=True)

Original comment by vcc.ch...@gmail.com on 24 Jan 2010 at 8:16