Can't save object using save() - AttributeError: 'DatabaseWrapper' object has no attribute 'Database'

195 views Asked by At

I have this class and I'm trying to create object by using shell:

class Task(models.Model):
    person = models.OneToOneField(Person)
    start_date = models.DateField(null=True)
    end_date = models.DateField(null=True)
    free_day = models.DateField(null=True)
    text = models.CharField(max_length=100)

    def __str__(self):
        return '%s' % self.person
p = Person.objects.get(username='Herehere')
t = Task(person=p,text='blabla')
t.save()

But I got this error:

AttributeError: 'DatabaseWrapper' object has no attribute 'Database'

If I change

person = models.OneToOneField(Person)

to

person = models.OneToOneField(Person, primary_key)

I got

'DatabaseWrapper' object has no attribute 'operators'

My settings.py db configurations:

DATABASES = {
    'default': {
        'ENGINE': 'django.db.backends.sqlite3',
        'NAME': os.path.join(BASE_DIR, 'db.sqlite3'),
    },
    'ldap': {
        'ENGINE': 'ldapdb.backends.ldap',
        'NAME': AUTH_LDAP_SERVER_URI,
        'USER': AUTH_LDAP_BIND_DN,
        'PASSWORD': AUTH_LDAP_BIND_PASSWORD,
    },
}
0

There are 0 answers