django.core.exceptions.ValidationError: [“'' value has an invalid date format. It must be in YYYY-MM-DD...





.everyoneloves__top-leaderboard:empty,.everyoneloves__mid-leaderboard:empty,.everyoneloves__bot-mid-leaderboard:empty{ height:90px;width:728px;box-sizing:border-box;
}







0















I using Django version 2.0.7 and I tried to make a Date Module Field Until I faced this error :



Date = models.DateField(blank=True, default='', null=True, help_text='today date.')


I used this code before and it worked but now after python manage.py makemigrations that I use python manage.py migrate I faced to this error.
full logs:



Operations to perform:
Apply all migrations: Blog, Portfolio, admin, auth, contenttypes, sessions
Running migrations:
Applying Blog.0002_auto_20180728_0218...Traceback (most recent call last):
File "manage.py", line 15, in <module>
execute_from_command_line(sys.argv)
File "D:LearnProjectsDjangomyvenvlibsite-packagesdjangocoremanagement__init__.py", line 371, in execute_from_command_line
utility.execute()
File "D:LearnProjectsDjangomyvenvlibsite-packagesdjangocoremanagement__init__.py", line 365, in execute
self.fetch_command(subcommand).run_from_argv(self.argv)
File "D:LearnProjectsDjangomyvenvlibsite-packagesdjangocoremanagementbase.py", line 288, in run_from_argv
self.execute(*args, **cmd_options)
File "D:LearnProjectsDjangomyvenvlibsite-packagesdjangocoremanagementbase.py", line 335, in execute
output = self.handle(*args, **options)
File "D:LearnProjectsDjangomyvenvlibsite-packagesdjangocoremanagementcommandsmigrate.py", line 200, in handle
fake_initial=fake_initial,
File "D:LearnProjectsDjangomyvenvlibsite-packagesdjangodbmigrationsexecutor.py", line 117, in migrate
state = self._migrate_all_forwards(state, plan, full_plan, fake=fake, fake_initial=fake_initial)
File "D:LearnProjectsDjangomyvenvlibsite-packagesdjangodbmigrationsexecutor.py", line 147, in _migrate_all_forwards
state = self.apply_migration(state, migration, fake=fake, fake_initial=fake_initial)
File "D:LearnProjectsDjangomyvenvlibsite-packagesdjangodbmigrationsexecutor.py", line 244, in apply_migration
state = migration.apply(state, schema_editor)
File "D:LearnProjectsDjangomyvenvlibsite-packagesdjangodbmigrationsmigration.py", line 122, in apply
operation.database_forwards(self.app_label, schema_editor, old_state, project_state)
File "D:LearnProjectsDjangomyvenvlibsite-packagesdjangodbmigrationsoperationsfields.py", line 216, in database_forwards
schema_editor.alter_field(from_model, from_field, to_field)
File "D:LearnProjectsDjangomyvenvlibsite-packagesdjangodbbackendsbaseschema.py", line 525, in alter_field
old_db_params, new_db_params, strict)
File "D:LearnProjectsDjangomyvenvlibsite-packagesdjangodbbackendspostgresqlschema.py", line 122, in _alter_field
new_db_params, strict,
File "D:LearnProjectsDjangomyvenvlibsite-packagesdjangodbbackendsbaseschema.py", line 629, in _alter_field
old_default = self.effective_default(old_field)
File "D:LearnProjectsDjangomyvenvlibsite-packagesdjangodbbackendsbaseschema.py", line 240, in effective_default
default = field.get_db_prep_save(default, self.connection)
File "D:LearnProjectsDjangomyvenvlibsite-packagesdjangodbmodelsfields__init__.py", line 767, in get_db_prep_save
return self.get_db_prep_value(value, connection=connection, prepared=False)
File "D:LearnProjectsDjangomyvenvlibsite-packagesdjangodbmodelsfields__init__.py", line 1276, in get_db_prep_value
value = self.get_prep_value(value)
File "D:LearnProjectsDjangomyvenvlibsite-packagesdjangodbmodelsfields__init__.py", line 1271, in get_prep_value
return self.to_python(value)
File "D:LearnProjectsDjangomyvenvlibsite-packagesdjangodbmodelsfields__init__.py", line 1246, in to_python
params={'value': value},
django.core.exceptions.ValidationError: ["'' value has an invalid date format. It must be in YYYY-MM-DD format."]


I even try to remove all migrations and db and make new migrationsbut it doesn't work too.
this link doesnt work for me too :
Resolving ValidationError: [u“'' value has an invalid date format. It must be in YYYY-MM-DD format.”] in Django 1.9.2?



In Addision, I'm sorry for writing mistakes in my question.










share|improve this question




















  • 1





    The default can not be the empty string, since that is not a Date.

    – Willem Van Onsem
    Jul 27 '18 at 21:58






  • 1





    so if i use '1111-11-11' value for default, its gonna works?

    – Ali
    Jul 27 '18 at 21:59






  • 1





    now I try a string , a number and '1111-11-11' too, but still not working.

    – Ali
    Jul 27 '18 at 22:00






  • 1





    No, for example date(1111, 11, 11) (with from datetime import date).

    – Willem Van Onsem
    Jul 27 '18 at 22:01






  • 1





    if you mean this : Date = models.DateField(blank=True, default=date(1111, 11, 11), null=True, help_text="Today Date.") its not work too and i still faced to same errorr.

    – Ali
    Jul 27 '18 at 22:04


















0















I using Django version 2.0.7 and I tried to make a Date Module Field Until I faced this error :



Date = models.DateField(blank=True, default='', null=True, help_text='today date.')


I used this code before and it worked but now after python manage.py makemigrations that I use python manage.py migrate I faced to this error.
full logs:



Operations to perform:
Apply all migrations: Blog, Portfolio, admin, auth, contenttypes, sessions
Running migrations:
Applying Blog.0002_auto_20180728_0218...Traceback (most recent call last):
File "manage.py", line 15, in <module>
execute_from_command_line(sys.argv)
File "D:LearnProjectsDjangomyvenvlibsite-packagesdjangocoremanagement__init__.py", line 371, in execute_from_command_line
utility.execute()
File "D:LearnProjectsDjangomyvenvlibsite-packagesdjangocoremanagement__init__.py", line 365, in execute
self.fetch_command(subcommand).run_from_argv(self.argv)
File "D:LearnProjectsDjangomyvenvlibsite-packagesdjangocoremanagementbase.py", line 288, in run_from_argv
self.execute(*args, **cmd_options)
File "D:LearnProjectsDjangomyvenvlibsite-packagesdjangocoremanagementbase.py", line 335, in execute
output = self.handle(*args, **options)
File "D:LearnProjectsDjangomyvenvlibsite-packagesdjangocoremanagementcommandsmigrate.py", line 200, in handle
fake_initial=fake_initial,
File "D:LearnProjectsDjangomyvenvlibsite-packagesdjangodbmigrationsexecutor.py", line 117, in migrate
state = self._migrate_all_forwards(state, plan, full_plan, fake=fake, fake_initial=fake_initial)
File "D:LearnProjectsDjangomyvenvlibsite-packagesdjangodbmigrationsexecutor.py", line 147, in _migrate_all_forwards
state = self.apply_migration(state, migration, fake=fake, fake_initial=fake_initial)
File "D:LearnProjectsDjangomyvenvlibsite-packagesdjangodbmigrationsexecutor.py", line 244, in apply_migration
state = migration.apply(state, schema_editor)
File "D:LearnProjectsDjangomyvenvlibsite-packagesdjangodbmigrationsmigration.py", line 122, in apply
operation.database_forwards(self.app_label, schema_editor, old_state, project_state)
File "D:LearnProjectsDjangomyvenvlibsite-packagesdjangodbmigrationsoperationsfields.py", line 216, in database_forwards
schema_editor.alter_field(from_model, from_field, to_field)
File "D:LearnProjectsDjangomyvenvlibsite-packagesdjangodbbackendsbaseschema.py", line 525, in alter_field
old_db_params, new_db_params, strict)
File "D:LearnProjectsDjangomyvenvlibsite-packagesdjangodbbackendspostgresqlschema.py", line 122, in _alter_field
new_db_params, strict,
File "D:LearnProjectsDjangomyvenvlibsite-packagesdjangodbbackendsbaseschema.py", line 629, in _alter_field
old_default = self.effective_default(old_field)
File "D:LearnProjectsDjangomyvenvlibsite-packagesdjangodbbackendsbaseschema.py", line 240, in effective_default
default = field.get_db_prep_save(default, self.connection)
File "D:LearnProjectsDjangomyvenvlibsite-packagesdjangodbmodelsfields__init__.py", line 767, in get_db_prep_save
return self.get_db_prep_value(value, connection=connection, prepared=False)
File "D:LearnProjectsDjangomyvenvlibsite-packagesdjangodbmodelsfields__init__.py", line 1276, in get_db_prep_value
value = self.get_prep_value(value)
File "D:LearnProjectsDjangomyvenvlibsite-packagesdjangodbmodelsfields__init__.py", line 1271, in get_prep_value
return self.to_python(value)
File "D:LearnProjectsDjangomyvenvlibsite-packagesdjangodbmodelsfields__init__.py", line 1246, in to_python
params={'value': value},
django.core.exceptions.ValidationError: ["'' value has an invalid date format. It must be in YYYY-MM-DD format."]


I even try to remove all migrations and db and make new migrationsbut it doesn't work too.
this link doesnt work for me too :
Resolving ValidationError: [u“'' value has an invalid date format. It must be in YYYY-MM-DD format.”] in Django 1.9.2?



In Addision, I'm sorry for writing mistakes in my question.










share|improve this question




















  • 1





    The default can not be the empty string, since that is not a Date.

    – Willem Van Onsem
    Jul 27 '18 at 21:58






  • 1





    so if i use '1111-11-11' value for default, its gonna works?

    – Ali
    Jul 27 '18 at 21:59






  • 1





    now I try a string , a number and '1111-11-11' too, but still not working.

    – Ali
    Jul 27 '18 at 22:00






  • 1





    No, for example date(1111, 11, 11) (with from datetime import date).

    – Willem Van Onsem
    Jul 27 '18 at 22:01






  • 1





    if you mean this : Date = models.DateField(blank=True, default=date(1111, 11, 11), null=True, help_text="Today Date.") its not work too and i still faced to same errorr.

    – Ali
    Jul 27 '18 at 22:04














0












0








0


3






I using Django version 2.0.7 and I tried to make a Date Module Field Until I faced this error :



Date = models.DateField(blank=True, default='', null=True, help_text='today date.')


I used this code before and it worked but now after python manage.py makemigrations that I use python manage.py migrate I faced to this error.
full logs:



Operations to perform:
Apply all migrations: Blog, Portfolio, admin, auth, contenttypes, sessions
Running migrations:
Applying Blog.0002_auto_20180728_0218...Traceback (most recent call last):
File "manage.py", line 15, in <module>
execute_from_command_line(sys.argv)
File "D:LearnProjectsDjangomyvenvlibsite-packagesdjangocoremanagement__init__.py", line 371, in execute_from_command_line
utility.execute()
File "D:LearnProjectsDjangomyvenvlibsite-packagesdjangocoremanagement__init__.py", line 365, in execute
self.fetch_command(subcommand).run_from_argv(self.argv)
File "D:LearnProjectsDjangomyvenvlibsite-packagesdjangocoremanagementbase.py", line 288, in run_from_argv
self.execute(*args, **cmd_options)
File "D:LearnProjectsDjangomyvenvlibsite-packagesdjangocoremanagementbase.py", line 335, in execute
output = self.handle(*args, **options)
File "D:LearnProjectsDjangomyvenvlibsite-packagesdjangocoremanagementcommandsmigrate.py", line 200, in handle
fake_initial=fake_initial,
File "D:LearnProjectsDjangomyvenvlibsite-packagesdjangodbmigrationsexecutor.py", line 117, in migrate
state = self._migrate_all_forwards(state, plan, full_plan, fake=fake, fake_initial=fake_initial)
File "D:LearnProjectsDjangomyvenvlibsite-packagesdjangodbmigrationsexecutor.py", line 147, in _migrate_all_forwards
state = self.apply_migration(state, migration, fake=fake, fake_initial=fake_initial)
File "D:LearnProjectsDjangomyvenvlibsite-packagesdjangodbmigrationsexecutor.py", line 244, in apply_migration
state = migration.apply(state, schema_editor)
File "D:LearnProjectsDjangomyvenvlibsite-packagesdjangodbmigrationsmigration.py", line 122, in apply
operation.database_forwards(self.app_label, schema_editor, old_state, project_state)
File "D:LearnProjectsDjangomyvenvlibsite-packagesdjangodbmigrationsoperationsfields.py", line 216, in database_forwards
schema_editor.alter_field(from_model, from_field, to_field)
File "D:LearnProjectsDjangomyvenvlibsite-packagesdjangodbbackendsbaseschema.py", line 525, in alter_field
old_db_params, new_db_params, strict)
File "D:LearnProjectsDjangomyvenvlibsite-packagesdjangodbbackendspostgresqlschema.py", line 122, in _alter_field
new_db_params, strict,
File "D:LearnProjectsDjangomyvenvlibsite-packagesdjangodbbackendsbaseschema.py", line 629, in _alter_field
old_default = self.effective_default(old_field)
File "D:LearnProjectsDjangomyvenvlibsite-packagesdjangodbbackendsbaseschema.py", line 240, in effective_default
default = field.get_db_prep_save(default, self.connection)
File "D:LearnProjectsDjangomyvenvlibsite-packagesdjangodbmodelsfields__init__.py", line 767, in get_db_prep_save
return self.get_db_prep_value(value, connection=connection, prepared=False)
File "D:LearnProjectsDjangomyvenvlibsite-packagesdjangodbmodelsfields__init__.py", line 1276, in get_db_prep_value
value = self.get_prep_value(value)
File "D:LearnProjectsDjangomyvenvlibsite-packagesdjangodbmodelsfields__init__.py", line 1271, in get_prep_value
return self.to_python(value)
File "D:LearnProjectsDjangomyvenvlibsite-packagesdjangodbmodelsfields__init__.py", line 1246, in to_python
params={'value': value},
django.core.exceptions.ValidationError: ["'' value has an invalid date format. It must be in YYYY-MM-DD format."]


I even try to remove all migrations and db and make new migrationsbut it doesn't work too.
this link doesnt work for me too :
Resolving ValidationError: [u“'' value has an invalid date format. It must be in YYYY-MM-DD format.”] in Django 1.9.2?



In Addision, I'm sorry for writing mistakes in my question.










share|improve this question
















I using Django version 2.0.7 and I tried to make a Date Module Field Until I faced this error :



Date = models.DateField(blank=True, default='', null=True, help_text='today date.')


I used this code before and it worked but now after python manage.py makemigrations that I use python manage.py migrate I faced to this error.
full logs:



Operations to perform:
Apply all migrations: Blog, Portfolio, admin, auth, contenttypes, sessions
Running migrations:
Applying Blog.0002_auto_20180728_0218...Traceback (most recent call last):
File "manage.py", line 15, in <module>
execute_from_command_line(sys.argv)
File "D:LearnProjectsDjangomyvenvlibsite-packagesdjangocoremanagement__init__.py", line 371, in execute_from_command_line
utility.execute()
File "D:LearnProjectsDjangomyvenvlibsite-packagesdjangocoremanagement__init__.py", line 365, in execute
self.fetch_command(subcommand).run_from_argv(self.argv)
File "D:LearnProjectsDjangomyvenvlibsite-packagesdjangocoremanagementbase.py", line 288, in run_from_argv
self.execute(*args, **cmd_options)
File "D:LearnProjectsDjangomyvenvlibsite-packagesdjangocoremanagementbase.py", line 335, in execute
output = self.handle(*args, **options)
File "D:LearnProjectsDjangomyvenvlibsite-packagesdjangocoremanagementcommandsmigrate.py", line 200, in handle
fake_initial=fake_initial,
File "D:LearnProjectsDjangomyvenvlibsite-packagesdjangodbmigrationsexecutor.py", line 117, in migrate
state = self._migrate_all_forwards(state, plan, full_plan, fake=fake, fake_initial=fake_initial)
File "D:LearnProjectsDjangomyvenvlibsite-packagesdjangodbmigrationsexecutor.py", line 147, in _migrate_all_forwards
state = self.apply_migration(state, migration, fake=fake, fake_initial=fake_initial)
File "D:LearnProjectsDjangomyvenvlibsite-packagesdjangodbmigrationsexecutor.py", line 244, in apply_migration
state = migration.apply(state, schema_editor)
File "D:LearnProjectsDjangomyvenvlibsite-packagesdjangodbmigrationsmigration.py", line 122, in apply
operation.database_forwards(self.app_label, schema_editor, old_state, project_state)
File "D:LearnProjectsDjangomyvenvlibsite-packagesdjangodbmigrationsoperationsfields.py", line 216, in database_forwards
schema_editor.alter_field(from_model, from_field, to_field)
File "D:LearnProjectsDjangomyvenvlibsite-packagesdjangodbbackendsbaseschema.py", line 525, in alter_field
old_db_params, new_db_params, strict)
File "D:LearnProjectsDjangomyvenvlibsite-packagesdjangodbbackendspostgresqlschema.py", line 122, in _alter_field
new_db_params, strict,
File "D:LearnProjectsDjangomyvenvlibsite-packagesdjangodbbackendsbaseschema.py", line 629, in _alter_field
old_default = self.effective_default(old_field)
File "D:LearnProjectsDjangomyvenvlibsite-packagesdjangodbbackendsbaseschema.py", line 240, in effective_default
default = field.get_db_prep_save(default, self.connection)
File "D:LearnProjectsDjangomyvenvlibsite-packagesdjangodbmodelsfields__init__.py", line 767, in get_db_prep_save
return self.get_db_prep_value(value, connection=connection, prepared=False)
File "D:LearnProjectsDjangomyvenvlibsite-packagesdjangodbmodelsfields__init__.py", line 1276, in get_db_prep_value
value = self.get_prep_value(value)
File "D:LearnProjectsDjangomyvenvlibsite-packagesdjangodbmodelsfields__init__.py", line 1271, in get_prep_value
return self.to_python(value)
File "D:LearnProjectsDjangomyvenvlibsite-packagesdjangodbmodelsfields__init__.py", line 1246, in to_python
params={'value': value},
django.core.exceptions.ValidationError: ["'' value has an invalid date format. It must be in YYYY-MM-DD format."]


I even try to remove all migrations and db and make new migrationsbut it doesn't work too.
this link doesnt work for me too :
Resolving ValidationError: [u“'' value has an invalid date format. It must be in YYYY-MM-DD format.”] in Django 1.9.2?



In Addision, I'm sorry for writing mistakes in my question.







django python-3.x django-models django-templates datefield






share|improve this question















share|improve this question













share|improve this question




share|improve this question








edited Jul 27 '18 at 21:58







Ali

















asked Jul 27 '18 at 21:57









AliAli

219114




219114








  • 1





    The default can not be the empty string, since that is not a Date.

    – Willem Van Onsem
    Jul 27 '18 at 21:58






  • 1





    so if i use '1111-11-11' value for default, its gonna works?

    – Ali
    Jul 27 '18 at 21:59






  • 1





    now I try a string , a number and '1111-11-11' too, but still not working.

    – Ali
    Jul 27 '18 at 22:00






  • 1





    No, for example date(1111, 11, 11) (with from datetime import date).

    – Willem Van Onsem
    Jul 27 '18 at 22:01






  • 1





    if you mean this : Date = models.DateField(blank=True, default=date(1111, 11, 11), null=True, help_text="Today Date.") its not work too and i still faced to same errorr.

    – Ali
    Jul 27 '18 at 22:04














  • 1





    The default can not be the empty string, since that is not a Date.

    – Willem Van Onsem
    Jul 27 '18 at 21:58






  • 1





    so if i use '1111-11-11' value for default, its gonna works?

    – Ali
    Jul 27 '18 at 21:59






  • 1





    now I try a string , a number and '1111-11-11' too, but still not working.

    – Ali
    Jul 27 '18 at 22:00






  • 1





    No, for example date(1111, 11, 11) (with from datetime import date).

    – Willem Van Onsem
    Jul 27 '18 at 22:01






  • 1





    if you mean this : Date = models.DateField(blank=True, default=date(1111, 11, 11), null=True, help_text="Today Date.") its not work too and i still faced to same errorr.

    – Ali
    Jul 27 '18 at 22:04








1




1





The default can not be the empty string, since that is not a Date.

– Willem Van Onsem
Jul 27 '18 at 21:58





The default can not be the empty string, since that is not a Date.

– Willem Van Onsem
Jul 27 '18 at 21:58




1




1





so if i use '1111-11-11' value for default, its gonna works?

– Ali
Jul 27 '18 at 21:59





so if i use '1111-11-11' value for default, its gonna works?

– Ali
Jul 27 '18 at 21:59




1




1





now I try a string , a number and '1111-11-11' too, but still not working.

– Ali
Jul 27 '18 at 22:00





now I try a string , a number and '1111-11-11' too, but still not working.

– Ali
Jul 27 '18 at 22:00




1




1





No, for example date(1111, 11, 11) (with from datetime import date).

– Willem Van Onsem
Jul 27 '18 at 22:01





No, for example date(1111, 11, 11) (with from datetime import date).

– Willem Van Onsem
Jul 27 '18 at 22:01




1




1





if you mean this : Date = models.DateField(blank=True, default=date(1111, 11, 11), null=True, help_text="Today Date.") its not work too and i still faced to same errorr.

– Ali
Jul 27 '18 at 22:04





if you mean this : Date = models.DateField(blank=True, default=date(1111, 11, 11), null=True, help_text="Today Date.") its not work too and i still faced to same errorr.

– Ali
Jul 27 '18 at 22:04












2 Answers
2






active

oldest

votes


















0














The default can not be the empty string, since that is not a Date.
for example use date(1111, 11, 11) with from datetime import date in modals page
then if you will be get same error , you have to delete all migrations and erase your database data too and do migrations again.






share|improve this answer



















  • 1





    for erase database data follow this: if you use sqllite the only thing that you have to do is that remove .sqllite3 for migration use this command : python manage.py makemigrations <appname> python manage.py migrate <appname> and if migrate command not work, use this instead: python manage.py migrate --fake

    – Ali
    Jul 27 '18 at 22:27





















0














import datetime

import pytz
from django.apps import AppConfig
from django.db.models.fields import DateTimeField
from django.utils.dateparse import parse_date
from django.core.exceptions import ValidationError

default_app_config = 'patch.PatchConfig'


def patch():
def get_db_prep_value(self, value, connection, prepared=False):
if isinstance(value, str):
if not value:
value = None
elif not parse_date(value):
try:
value = datetime.datetime.fromtimestamp(int(value)).replace(tzinfo=pytz.UTC)
except:
raise ValidationError(
self.error_messages['invalid'],
code='invalid',
params={'value': value},
)
if not prepared:
value = self.get_prep_value(value)
return connection.ops.adapt_datetimefield_value(value)

DateTimeField.get_db_prep_value = get_db_prep_value


class PatchConfig(AppConfig):
name = 'patch'

def ready(self):
patch()


You may be need this patch






share|improve this answer


























    Your Answer






    StackExchange.ifUsing("editor", function () {
    StackExchange.using("externalEditor", function () {
    StackExchange.using("snippets", function () {
    StackExchange.snippets.init();
    });
    });
    }, "code-snippets");

    StackExchange.ready(function() {
    var channelOptions = {
    tags: "".split(" "),
    id: "1"
    };
    initTagRenderer("".split(" "), "".split(" "), channelOptions);

    StackExchange.using("externalEditor", function() {
    // Have to fire editor after snippets, if snippets enabled
    if (StackExchange.settings.snippets.snippetsEnabled) {
    StackExchange.using("snippets", function() {
    createEditor();
    });
    }
    else {
    createEditor();
    }
    });

    function createEditor() {
    StackExchange.prepareEditor({
    heartbeatType: 'answer',
    autoActivateHeartbeat: false,
    convertImagesToLinks: true,
    noModals: true,
    showLowRepImageUploadWarning: true,
    reputationToPostImages: 10,
    bindNavPrevention: true,
    postfix: "",
    imageUploader: {
    brandingHtml: "Powered by u003ca class="icon-imgur-white" href="https://imgur.com/"u003eu003c/au003e",
    contentPolicyHtml: "User contributions licensed under u003ca href="https://creativecommons.org/licenses/by-sa/3.0/"u003ecc by-sa 3.0 with attribution requiredu003c/au003e u003ca href="https://stackoverflow.com/legal/content-policy"u003e(content policy)u003c/au003e",
    allowUrls: true
    },
    onDemand: true,
    discardSelector: ".discard-answer"
    ,immediatelyShowMarkdownHelp:true
    });


    }
    });














    draft saved

    draft discarded


















    StackExchange.ready(
    function () {
    StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f51566024%2fdjango-core-exceptions-validationerror-value-has-an-invalid-date-format-i%23new-answer', 'question_page');
    }
    );

    Post as a guest















    Required, but never shown

























    2 Answers
    2






    active

    oldest

    votes








    2 Answers
    2






    active

    oldest

    votes









    active

    oldest

    votes






    active

    oldest

    votes









    0














    The default can not be the empty string, since that is not a Date.
    for example use date(1111, 11, 11) with from datetime import date in modals page
    then if you will be get same error , you have to delete all migrations and erase your database data too and do migrations again.






    share|improve this answer



















    • 1





      for erase database data follow this: if you use sqllite the only thing that you have to do is that remove .sqllite3 for migration use this command : python manage.py makemigrations <appname> python manage.py migrate <appname> and if migrate command not work, use this instead: python manage.py migrate --fake

      – Ali
      Jul 27 '18 at 22:27


















    0














    The default can not be the empty string, since that is not a Date.
    for example use date(1111, 11, 11) with from datetime import date in modals page
    then if you will be get same error , you have to delete all migrations and erase your database data too and do migrations again.






    share|improve this answer



















    • 1





      for erase database data follow this: if you use sqllite the only thing that you have to do is that remove .sqllite3 for migration use this command : python manage.py makemigrations <appname> python manage.py migrate <appname> and if migrate command not work, use this instead: python manage.py migrate --fake

      – Ali
      Jul 27 '18 at 22:27
















    0












    0








    0







    The default can not be the empty string, since that is not a Date.
    for example use date(1111, 11, 11) with from datetime import date in modals page
    then if you will be get same error , you have to delete all migrations and erase your database data too and do migrations again.






    share|improve this answer













    The default can not be the empty string, since that is not a Date.
    for example use date(1111, 11, 11) with from datetime import date in modals page
    then if you will be get same error , you have to delete all migrations and erase your database data too and do migrations again.







    share|improve this answer












    share|improve this answer



    share|improve this answer










    answered Jul 27 '18 at 22:24









    AliAli

    219114




    219114








    • 1





      for erase database data follow this: if you use sqllite the only thing that you have to do is that remove .sqllite3 for migration use this command : python manage.py makemigrations <appname> python manage.py migrate <appname> and if migrate command not work, use this instead: python manage.py migrate --fake

      – Ali
      Jul 27 '18 at 22:27
















    • 1





      for erase database data follow this: if you use sqllite the only thing that you have to do is that remove .sqllite3 for migration use this command : python manage.py makemigrations <appname> python manage.py migrate <appname> and if migrate command not work, use this instead: python manage.py migrate --fake

      – Ali
      Jul 27 '18 at 22:27










    1




    1





    for erase database data follow this: if you use sqllite the only thing that you have to do is that remove .sqllite3 for migration use this command : python manage.py makemigrations <appname> python manage.py migrate <appname> and if migrate command not work, use this instead: python manage.py migrate --fake

    – Ali
    Jul 27 '18 at 22:27







    for erase database data follow this: if you use sqllite the only thing that you have to do is that remove .sqllite3 for migration use this command : python manage.py makemigrations <appname> python manage.py migrate <appname> and if migrate command not work, use this instead: python manage.py migrate --fake

    – Ali
    Jul 27 '18 at 22:27















    0














    import datetime

    import pytz
    from django.apps import AppConfig
    from django.db.models.fields import DateTimeField
    from django.utils.dateparse import parse_date
    from django.core.exceptions import ValidationError

    default_app_config = 'patch.PatchConfig'


    def patch():
    def get_db_prep_value(self, value, connection, prepared=False):
    if isinstance(value, str):
    if not value:
    value = None
    elif not parse_date(value):
    try:
    value = datetime.datetime.fromtimestamp(int(value)).replace(tzinfo=pytz.UTC)
    except:
    raise ValidationError(
    self.error_messages['invalid'],
    code='invalid',
    params={'value': value},
    )
    if not prepared:
    value = self.get_prep_value(value)
    return connection.ops.adapt_datetimefield_value(value)

    DateTimeField.get_db_prep_value = get_db_prep_value


    class PatchConfig(AppConfig):
    name = 'patch'

    def ready(self):
    patch()


    You may be need this patch






    share|improve this answer






























      0














      import datetime

      import pytz
      from django.apps import AppConfig
      from django.db.models.fields import DateTimeField
      from django.utils.dateparse import parse_date
      from django.core.exceptions import ValidationError

      default_app_config = 'patch.PatchConfig'


      def patch():
      def get_db_prep_value(self, value, connection, prepared=False):
      if isinstance(value, str):
      if not value:
      value = None
      elif not parse_date(value):
      try:
      value = datetime.datetime.fromtimestamp(int(value)).replace(tzinfo=pytz.UTC)
      except:
      raise ValidationError(
      self.error_messages['invalid'],
      code='invalid',
      params={'value': value},
      )
      if not prepared:
      value = self.get_prep_value(value)
      return connection.ops.adapt_datetimefield_value(value)

      DateTimeField.get_db_prep_value = get_db_prep_value


      class PatchConfig(AppConfig):
      name = 'patch'

      def ready(self):
      patch()


      You may be need this patch






      share|improve this answer




























        0












        0








        0







        import datetime

        import pytz
        from django.apps import AppConfig
        from django.db.models.fields import DateTimeField
        from django.utils.dateparse import parse_date
        from django.core.exceptions import ValidationError

        default_app_config = 'patch.PatchConfig'


        def patch():
        def get_db_prep_value(self, value, connection, prepared=False):
        if isinstance(value, str):
        if not value:
        value = None
        elif not parse_date(value):
        try:
        value = datetime.datetime.fromtimestamp(int(value)).replace(tzinfo=pytz.UTC)
        except:
        raise ValidationError(
        self.error_messages['invalid'],
        code='invalid',
        params={'value': value},
        )
        if not prepared:
        value = self.get_prep_value(value)
        return connection.ops.adapt_datetimefield_value(value)

        DateTimeField.get_db_prep_value = get_db_prep_value


        class PatchConfig(AppConfig):
        name = 'patch'

        def ready(self):
        patch()


        You may be need this patch






        share|improve this answer















        import datetime

        import pytz
        from django.apps import AppConfig
        from django.db.models.fields import DateTimeField
        from django.utils.dateparse import parse_date
        from django.core.exceptions import ValidationError

        default_app_config = 'patch.PatchConfig'


        def patch():
        def get_db_prep_value(self, value, connection, prepared=False):
        if isinstance(value, str):
        if not value:
        value = None
        elif not parse_date(value):
        try:
        value = datetime.datetime.fromtimestamp(int(value)).replace(tzinfo=pytz.UTC)
        except:
        raise ValidationError(
        self.error_messages['invalid'],
        code='invalid',
        params={'value': value},
        )
        if not prepared:
        value = self.get_prep_value(value)
        return connection.ops.adapt_datetimefield_value(value)

        DateTimeField.get_db_prep_value = get_db_prep_value


        class PatchConfig(AppConfig):
        name = 'patch'

        def ready(self):
        patch()


        You may be need this patch







        share|improve this answer














        share|improve this answer



        share|improve this answer








        edited Nov 22 '18 at 7:51

























        answered Nov 22 '18 at 7:33









        user9622779user9622779

        11




        11






























            draft saved

            draft discarded




















































            Thanks for contributing an answer to Stack Overflow!


            • Please be sure to answer the question. Provide details and share your research!

            But avoid



            • Asking for help, clarification, or responding to other answers.

            • Making statements based on opinion; back them up with references or personal experience.


            To learn more, see our tips on writing great answers.




            draft saved


            draft discarded














            StackExchange.ready(
            function () {
            StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f51566024%2fdjango-core-exceptions-validationerror-value-has-an-invalid-date-format-i%23new-answer', 'question_page');
            }
            );

            Post as a guest















            Required, but never shown





















































            Required, but never shown














            Required, but never shown












            Required, but never shown







            Required, but never shown

































            Required, but never shown














            Required, but never shown












            Required, but never shown







            Required, but never shown







            Popular posts from this blog

            Guess what letter conforming each word

            Port of Spain

            Run scheduled task as local user group (not BUILTIN)