I get the bellow error in the console, when I run server in my PyCharm:
ERRORS:
frontend.Users.ctime: (fields.E160) The options auto_now, auto_now_add, and default are mutually exclusive. Only one of these options may be present.
frontend.Users.uptime: (fields.E160) The options auto_now, auto_now_add, and default are mutually exclusive. Only one of these options may be present.
My models Users code is below:
class Users(models.Model):
ctime = models.DateTimeField(auto_now_add=True, default=datetime.now())
uptime = models.DateTimeField(auto_now=True, default=datetime.now())
Why I get this error?
Just use:
class Users(models.Model):
ctime = models.DateTimeField(auto_now_add=True)
uptime = models.DateTimeField(auto_now=True)
It will work.
Explanation:
These both are mutually exclusive means you should use only one of them, not both.
I got the same error below:
ERRORS: app1.Person.updated_at: (fields.E160) The options auto_now, auto_now_add, and default are mutually exclusive. Only one of these options may be present.
Because I set both auto_now=True and auto_now_add=True to DateTimeField() as shown below:
# "app1/models.py"
class Person(models.Model):
...
updated_at = models.DateTimeField(
auto_now=True, # Here
auto_now_add=True # Here
)
...
So, I removed one of them as shown below, then the error was solved:
# "app1/models.py"
class Person(models.Model):
...
updated_at = models.DateTimeField(
# auto_now=True, # Here
auto_now_add=True
)
...
# "app1/models.py"
class Person(models.Model):
...
updated_at = models.DateTimeField(
auto_now=True,
# auto_now_add=True # Here
)
...
In addition, the doc says below in DateField.auto_now_add:
The options
auto_now_add,auto_now, anddefaultare mutually exclusive. Any combination of these options will result in an error.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With