timezone() missing required argument 'offset' (pos 1) in models.py while trying to migrate, what is the reason?

rony01

while making a blog, my models.py:

from django.db import models

class Post(models.Model):
    title=models.CharField(max_length=200,blank=True)
    author=models.ForeignKey('auth.user',on_delete=models.CASCADE,)
    image=models.ImageField(upload_to='media/',blank=True)
    content=models.CharField(max_length=1000,blank=True)
    date=models.DateTimeField(auto_now_add=False, editable=False)
    tag=models.CharField(max_length=100,blank=True)
    slug=models.CharField(max_length=200,blank=True)
    def __str__(self):
       return self.title

when i run python manage.py makemigrations, datefield is created in database:

from django.db import migrations, models
class Migration(migrations.Migration):
dependencies = [
    ('blog', '0013_auto_20191124_1448'),
]

operations = [
    migrations.AlterField(
        model_name='post',
        name='date',
        field=models.DateTimeField(editable=False),
    ),
]

but when i try to run python manage.py migrate, it shows the following error:

(Django-k7xSBAPV) C:\Myfiles\python\Django\myblog\blog_project>python manage.py 
makemigrations
No changes detected

(Django-k7xSBAPV) C:\.....\blog_project>python manage.py migrate
Operations to perform:
Apply all migrations: admin, auth, blog, contenttypes, sessions
Running migrations:
Applying blog.0004_post_date...Traceback (most recent call last):
File "manage.py", line 21, in <module>
main()
File "manage.py", line 17, in main
execute_from_command_line(sys.argv)
File "C:\Users\ronyrocks\.virtualenvs\Django-k7xSBAPV\lib\site-
packages\django\core\management\__init__.py", line 381, in 
execute_from_command_line
utility.execute()
File "C:\Users\ronyrocks\.virtualenvs\Django-k7xSBAPV\lib\site-
packages\django\core\management\__init__.py", line 375, in execute
self.fetch_command(subcommand).run_from_argv(self.argv)
File "C:\Users\ronyrocks\.virtualenvs\Django-k7xSBAPV\lib\site-
packages\django\core\management\base.py", line 323, in run_from_argv
self.execute(*args, **cmd_options)
File "C:\Users\ronyrocks\.virtualenvs\Django-k7xSBAPV\lib\site-
packages\django\core\management\base.py", line 364, in execute
output = self.handle(*args, **options)
File "C:\Users\ronyrocks\.virtualenvs\Django-k7xSBAPV\lib\site-
packages\django\core\management\base.py", line 83, in wrapped 
res = handle_func(*args, **kwargs)
File "C:\Users\ronyrocks\.virtualenvs\Django-k7xSBAPV\lib\site-
packages\django\core\management\commands\migrate.py", line 234, in handle
fake_initial=fake_initial,
File "C:\Users\ronyrocks\.virtualenvs\Django-k7xSBAPV\lib\site-
packages\django\db\migrations\executor.py", line 117, in migrate
state = self._migrate_all_forwards(state, plan, full_plan, fake=fake, 
fake_initial=fake_initial)
File "C:\Users\ronyrocks\.virtualenvs\Django-k7xSBAPV\lib\site-
packages\django\db\migrations\executor.py", line 147, in _migrate_all_forwards
state = self.apply_migration(state, migration, fake=fake, 
fake_initial=fake_initial)
File "C:\Users\ronyrocks\.virtualenvs\Django-k7xSBAPV\lib\site-
packages\django\db\migrations\executor.py", line 245, in apply_migration
state = migration.apply(state, schema_editor)
File "C:\Users\ronyrocks\.virtualenvs\Django-k7xSBAPV\lib\site-
packages\django\db\migrations\migration.py", line 124, in apply
operation.database_forwards(self.app_label, schema_editor, old_state, 
project_state)
File "C:\Users\ronyrocks\.virtualenvs\Django-k7xSBAPV\lib\site-
packages\django\db\migrations\operations\fields.py", line 112, in database_forwards field,
File "C:\Users\ronyrocks\.virtualenvs\Django-k7xSBAPV\lib\site-
packages\django\db\backends\sqlite3\schema.py", line 327, in add_field
self._remake_table(model, create_field=field)
File "C:\Users\ronyrocks\.virtualenvs\Django-k7xSBAPV\lib\site-
packages\django\db\backends\sqlite3\schema.py", line 188, in _reremake_table
self.effective_default(create_field)
File "C:\Users\ronyrocks\.virtualenvs\Django-k7xSBAPV\lib\site-
packages\django\db\backends\base\schema.py", line 233, in effectctive_default
return field.get_db_prep_save(self._effective_default(field), self.connection)
File "C:\Users\ronyrocks\.virtualenvs\Django-k7xSBAPV\lib\site-
packages\django\db\backends\base\schema.py", line 212, in _effecective_default
default = field.get_default()
File "C:\Users\ronyrocks\.virtualenvs\Django-k7xSBAPV\lib\site-
packages\django\db\models\fields\__init__.py", line 801, in get_t_default
return self._get_default()
TypeError: timezone() missing required argument 'offset' (pos 1)

but without date in models.py, everything was working fine. i tried to use dafault=timezone.now() along with from django.utils.timezone import * but it's showing different warning.

please give me some suggestions. i am doing this in django2.2.

rony01

i think i solved the problem. i am sharing it if anyone wish to look through.... and i have polished the code...

from django.db import models
from django.utils import timezone
class Post(models.Model):
    title=models.CharField(max_length=200)
    author=models.ForeignKey(
                        'auth.User',on_delete=models.CASCADE,)
    image=models.ImageField(upload_to='media/',blank=True)
    content=models.CharField(max_length=1000)
    date=models.DateTimeField(default=timezone.now)
    tag=models.CharField(max_length=100)
    slug=models.CharField(max_length=200)
    def __str__(self):
       return self.title
    def publish_time(self):
       publication=timezone.now()
       self.save()

My main issue was i forget to migrate when i first created the app. i am not sure this is the main reason or not. but it worked smoothly.besides i have decided to use ckeditor, but it poses another problem which it just accepts picture from the link. that's why i prefer more ImageField....

any way this model.py file ran at first attempt while starting a clean app.

thanx again

Collected from the Internet

Please contact [email protected] to delete if infringement.

edited at
0

Comments

0 comments
Login to comment

Related

Got "function missing required argument 'month' (pos 2)" error while adding a DateField to models.py

Python TypeError: Required argument 'offset' (pos 1) not found

TypeError: open() missing required argument 'file' (pos 1)

TypeError: destroyWindow() missing required argument 'winname' (pos 1)

Keras,models.add() missing 1 required positional argument: 'layer'

Error - function missing required argument 'month' (pos 2), is displayed when trying to fetch time in fixed format

Trying to make a barchart, bar() missing 1 required positional argument: 'height'

Exception while trying to load openNLP POS models

TypeError: missing 1 required positional argument while using pytest fixture

missing 1 required positional argument: 'self' while using classmethod in staticmethod

missing 1 required positional argument

How to get first value in groupby , TypeError: first() missing 1 required positional argument: 'offset'

Discord.py missing required argument

Python TypeError: UMat() missing required argument 'ranges' (pos 2)

Missing 1 required positional argument: 'self' missing

Discord.py - on_reaction_add() missing 1 required positional argument: 'user'

Discord.py Rewrite Cog: TypeError: __init__() missing 1 required positional argument: 'func'

Discord.py on_raw_reaction_add() missing 1 required positional argument: 'user'

discord.py on_message_delete TypeError: on_message_delete() missing 1 required positional argument: 'message'

(discord.py) TypeError: to_components() missing 1 required positional argument: 'self'

Trying to fix TypeError: freqRolls() missing 1 required positional argument: 'sides' python

Django TypeError missing 1 required positional argument when trying to use form input in another function

Argument is missing while trying to add surface (R)

Django python: Using DateInput --Required argument 'year' (pos 1) not found

hexdigest() throws TypeError: Required argument 'length' (pos 1) not found

Error while calling python function, TypeError: returnbook() missing 1 required positional argument: 'self'

Django - "missing 1 required positional argument: 'self' " error, while uploading Image

TypeError: __init__() missing 1 required positional argument: 'units' while coding an neural net

TypeError: all() missing 1 required positional argument: 'self' while using AbstractUser model

TOP Ranking

  1. 1

    Failed to listen on localhost:8000 (reason: Cannot assign requested address)

  2. 2

    Loopback Error: connect ECONNREFUSED 127.0.0.1:3306 (MAMP)

  3. 3

    How to import an asset in swift using Bundle.main.path() in a react-native native module

  4. 4

    pump.io port in URL

  5. 5

    Compiler error CS0246 (type or namespace not found) on using Ninject in ASP.NET vNext

  6. 6

    BigQuery - concatenate ignoring NULL

  7. 7

    ngClass error (Can't bind ngClass since it isn't a known property of div) in Angular 11.0.3

  8. 8

    ggplotly no applicable method for 'plotly_build' applied to an object of class "NULL" if statements

  9. 9

    Spring Boot JPA PostgreSQL Web App - Internal Authentication Error

  10. 10

    How to remove the extra space from right in a webview?

  11. 11

    java.lang.NullPointerException: Cannot read the array length because "<local3>" is null

  12. 12

    Jquery different data trapped from direct mousedown event and simulation via $(this).trigger('mousedown');

  13. 13

    flutter: dropdown item programmatically unselect problem

  14. 14

    How to use merge windows unallocated space into Ubuntu using GParted?

  15. 15

    Change dd-mm-yyyy date format of dataframe date column to yyyy-mm-dd

  16. 16

    Nuget add packages gives access denied errors

  17. 17

    Svchost high CPU from Microsoft.BingWeather app errors

  18. 18

    Can't pre-populate phone number and message body in SMS link on iPhones when SMS app is not running in the background

  19. 19

    12.04.3--- Dconf Editor won't show com>canonical>unity option

  20. 20

    Any way to remove trailing whitespace *FOR EDITED* lines in Eclipse [for Java]?

  21. 21

    maven-jaxb2-plugin cannot generate classes due to two declarations cause a collision in ObjectFactory class

HotTag

Archive