On 2015-09-22 17:29, Nikolas Stevenson-Molnar wrote:
It's telling you that your default "date" value will be the same for
every instance of "Journal" you create (essentially it'll be the time
when the migration is created), when you probably intend it to be the
time each Journal entry is created.
Try changing default=timezone.now() to default=timezone.now (without
the parens). That should resolve the warning and yield more desirable
behavior. Even better, remove the default and add
auto_now_add=True
(https://docs.djangoproject.com/en/1.8/ref/models/fields/#django.db.models.DateField.auto_now_add)
Thank you,_Nik.
That did indeed resolve this issue and I am grateful to you.
Now I have another: I'm unable to make django forget what I've done
before!
I still get the following error:
"""
(venv)alex@x301:~/Py/debk$ ./manage.py makemigrations
Did you rename lineitems.acount to lineitems.dc_type (a CharField)?
[y/N] y
You are trying to add a non-nullable field 'acnt_number' to lineitems
without a default; we can't do that (the database needs something to
populate existing rows).
Please select a fix:
1) Provide a one-off default now (will be set on all existing rows)
2) Quit, and let me add a default in models.py
Select an option:
"""
As mentioned before, I deleted my data base but the error persists
Here's journal/models.py currently:
from django.db import models
ACCOUNT_CODE_LENGTH = 4
class Journal(models.Model):
"""
Each instance represents a journal entry to be stored in the
Journal table. The automatically created auto-incrementing
primary key serves as the entry number.
"""
date = models.DateTimeField(auto_now_add=True)
user = models.CharField(max_length=24)
description = models.CharField(max_length=256)
def __str__(self):
ret = [" #{:0>3} on {:<12} by {}."
.format(self.id,
self.date.strftime('%Y-%m-%d %H:%M'),
self.user)]
for line in self.description.split('\n'):
ret.append(" {}".format(line))
return '\n'.join(ret)
class LineItems(models.Model):
entry = models.ForeignKey(Journal)
acnt_number = models.CharField(max_length=ACCOUNT_CODE_LENGTH)
dc_type = models.CharField(max_length=1) # D(ebit or C(redit
amount = models.IntegerField() # Pennies i.e. $nn.dd * 100
def __str__(self):
if self.dc_type.upper() == 'D':
return ("{:>8}:{:>10,.2f}Dr"
.format(self.acnt_number, self.amount/100.0))
elif self.dc_type.upper() == 'C':
return ("{:>8}:{:>20,.2f}Cr"
.format(self.acnt_number, self.amount/100.0))
else:
return ("Huston, we have a problem!")
How does Django even know what was in this file before, let alone why
should it now care?
--
You received this message because you are subscribed to the Google Groups "Django
users" group.
To unsubscribe from this group and stop receiving emails from it, send an email
to django-users+unsubscr...@googlegroups.com.
To post to this group, send email to django-users@googlegroups.com.
Visit this group at http://groups.google.com/group/django-users.
To view this discussion on the web visit
https://groups.google.com/d/msgid/django-users/fcf47bd983b673fca2c308d4f3f63b22%40sonic.net.
For more options, visit https://groups.google.com/d/optout.