#26839 closed Uncategorized (invalid)
Migrate: TypeError: 'module' object is not callable
Reported by: | Henrique Chehad | Owned by: | nobody |
---|---|---|---|
Component: | Migrations | Version: | 1.9 |
Severity: | Normal | Keywords: | |
Cc: | Triage Stage: | Unreviewed | |
Has patch: | no | Needs documentation: | no |
Needs tests: | no | Patch needs improvement: | no |
Easy pickings: | no | UI/UX: | no |
Description
I used makemigrations and after migrate command:
Traceback (most recent call last): File "manage.py", line 10, in <module> execute_from_command_line(sys.argv) File "/usr/local/lib/python2.7/dist-packages/django/core/management/__init__.py", line 353, in execute_from_command_line utility.execute() File "/usr/local/lib/python2.7/dist-packages/django/core/management/__init__.py", line 345, in execute self.fetch_command(subcommand).run_from_argv(self.argv) File "/usr/local/lib/python2.7/dist-packages/django/core/management/base.py", line 348, in run_from_argv self.execute(*args, **cmd_options) File "/usr/local/lib/python2.7/dist-packages/raven/contrib/django/management/__init__.py", line 41, in new_execute return original_func(self, *args, **kwargs) File "/usr/local/lib/python2.7/dist-packages/django/core/management/base.py", line 399, in execute output = self.handle(*args, **options) File "/usr/local/lib/python2.7/dist-packages/django/core/management/commands/migrate.py", line 89, in handle executor = MigrationExecutor(connection, self.migration_progress_callback) File "/usr/local/lib/python2.7/dist-packages/django/db/migrations/executor.py", line 20, in __init__ self.loader = MigrationLoader(self.connection) File "/usr/local/lib/python2.7/dist-packages/django/db/migrations/loader.py", line 49, in __init__ self.build_graph() File "/usr/local/lib/python2.7/dist-packages/django/db/migrations/loader.py", line 170, in build_graph self.load_disk() File "/usr/local/lib/python2.7/dist-packages/django/db/migrations/loader.py", line 105, in load_disk migration_module = import_module("%s.%s" % (module_name, migration_name)) File "/usr/lib/python2.7/importlib/__init__.py", line 37, in import_module __import__(name) File "/root/filmow/src/filmow/quizzes/migrations/0001_initial.py", line 12, in <module> class Migration(migrations.Migration): File "/root/filmow/src/filmow/quizzes/migrations/0001_initial.py", line 63, in Migration ('end_date', models.DateTimeField(default=datetime(2016, 7, 4, 15, 18, 59, 481979))), TypeError: 'module' object is not callable
I tested with 1.9.5 and 1.9.3 versions
Change History (7)
comment:1 by , 8 years ago
Resolution: | → needsinfo |
---|---|
Status: | new → closed |
comment:2 by , 8 years ago
The migration line with issue is it:
('end_date', models.DateTimeField(default=datetime(2016, 7, 4, 15, 18, 59, 481979))),
Import:
# -*- coding: utf-8 -*- # Generated by Django 1.9.5 on 2016-07-04 15:19 from __future__ import unicode_literals import datetime
I changed "import datetime" to "from datetime import datetime" and fixed the issue.
But I don't know why Django generated migration file using datetime instead datetime.datetime.
comment:3 by , 8 years ago
What's you model's end_date
default? I tried reproducing with datetime.datetime.now()
and datetime(2016, 7, 4, 15, 18, 59, 481979)
and in both cases the appropriate object (datetime.datetime
) was imported correctly in the generated migration.
comment:4 by , 8 years ago
Thank you. Located the problem. Is local.
The default option calls another code that have the bellow code:
try: from django.utils.timezone import utc, now, today except ImportError: return datetime.now()
Django 1.9 doesn't have the path "django.utils.timezone.now"
The ImportError returns the wrong value!
Thank you!
comment:5 by , 8 years ago
Resolution: | needsinfo → fixed |
---|
comment:6 by , 8 years ago
Resolution: | fixed → invalid |
---|
comment:7 by , 6 years ago
This error statement TypeError: 'module' object is not callable is raised as you are being confused about the Class name and Module name. The problem is in the import line . You are importing a module, not a class. This happend because the module name and class name have the same name .
If you have a class "MyClass" in a file called "MyClass.py" , then you should import :
from MyClass import MyClass
In Python , a script is a module, whose name is determined by the filename . So when you start out your file MyClass.py with import MyClass you are creating a loop in the module structure.
In Python, everything (including functions, methods, modules, classes etc.) is an object , and methods are just attributes like every others. So,there's no separate namespaces for methods. So when you set an instance attribute, it shadows the class attribute by the same name. The obvious solution is to give attributes different names.
Please provide the content of the
quizzes/migrations/0001_initial.py
file to help us investigate further. It looks like both thedatetime.datetime
class and thedatetime
module were imported and are conflicting somehow.