starkshang
starkshang

Reputation: 8578

makemigrations not identifying database changes

I'm using django,now I renamed a python file from custom_fields to fields and change a Model class,and the Model class is using a field comes from fields file,but when I run

python manage.py makemigrations

such error exists:

Traceback (most recent call last):
File "manage.py", line 10, in <module>
    execute_from_command_line(sys.argv)
File "/Users/smy/wuque/projects/LinuxChat/Server/lib/python2.7/site-packages/django/core/management/__init__.py", line 350, in execute_from_command_line
    utility.execute()
File "/Users/smy/wuque/projects/LinuxChat/Server/lib/python2.7/site-packages/django/core/management/__init__.py", line 342, in execute
    self.fetch_command(subcommand).run_from_argv(self.argv)
File "/Users/smy/wuque/projects/LinuxChat/Server/lib/python2.7/site-packages/django/core/management/base.py", line 348, in run_from_argv
    self.execute(*args, **cmd_options)
File "/Users/smy/wuque/projects/LinuxChat/Server/lib/python2.7/site-packages/django/core/management/base.py", line 399, in execute
    output = self.handle(*args, **options)
File "/Users/smy/wuque/projects/LinuxChat/Server/lib/python2.7/site-packages/django/core/management/commands/makemigrations.py", line 65, in handle
    loader = MigrationLoader(None, ignore_no_migrations=True)
File "/Users/smy/wuque/projects/LinuxChat/Server/lib/python2.7/site-packages/django/db/migrations/loader.py", line 49, in __init__
    self.build_graph()
File "/Users/smy/wuque/projects/LinuxChat/Server/lib/python2.7/site-packages/django/db/migrations/loader.py", line 170, in build_graph
    self.load_disk()
File "/Users/smy/wuque/projects/LinuxChat/Server/lib/python2.7/site-packages/django/db/migrations/loader.py", line 105, in load_disk
    migration_module = import_module("%s.%s" % (module_name, migration_name))
File "/System/Library/Frameworks/Python.framework/Versions/2.7/lib/python2.7/importlib/__init__.py", line 37, in import_module
    __import__(name)
File "/Users/smy/wuque/projects/LinuxChat/Server/LinuxChatServer/Server/migrations/0005_auto_20151215_1223.py", line 5, in <module>
    import Server.custom_fields
ImportError: No module named custom_fields

I don't know how to solve this error,so I try to delete migrates folder,but when I run above command again,nothing changed can be detected,even I modify Model class again.Just show:

No changes detected.

Now I can't modify database table,anyone can tell me how to solve this problem?thanks!

Upvotes: 1

Views: 149

Answers (2)

Maneesh
Maneesh

Reputation: 144

If it is the first time you are migrating that app you have to use:

manage.py makemigrations myappname

Once you do that you can do:

manage.py migrate

Running makemigrations in the project folder means it will look to update all the tables related to all the apps included in settings.py for the project. Once you include it, makemigrations will automatically include the app (this saves a lot of work so you don't have to run makemigrations app_name for every app in your project/site).

If you confused any of these steps, read the migration files. Change them to correct your schema or remove unwanted files but don't forget to change next migration file's dependencies part .

Upvotes: 1

Sayse
Sayse

Reputation: 43330

makemigrations is done to apply changes that will directly affect the underlying structure of a database.

Renaming your python file will have no affect whatsoever on the database since the type of field hasn't changed and thus it won't have any affect on the database. All you end up seeing is a different import in your python file.

Upvotes: 2

Related Questions