修改后无法将makemigrations应用于模型

时间:2019-07-28 15:20:01

标签: python django django-models

我在models.py中为我的Django应用实现了一个模型。一切正常。然后,我尝试向模型添加一个新字段。如果现在运行“ makemigrations”,则会出现错误“表movieapp_movie_class没有名为show_movie的列”。我以为运行makemigrations是将此列添加到表中的命令。

我尝试删除db.sqlite3和迁移在应用程序文件夹中的文件夹,但这些文件夹无效。

from django.db import models

# Create your models here.
class movie_class(models.Model):
    show_movie = models.CharField(max_length=100) # this is the new property I wanted to add
    movie_id = models.CharField(max_length=100)
    title = models.CharField(max_length=100)
    rating = models.CharField(max_length=100)
    poster = models.CharField(max_length=100)

跟踪:

(movies) C:\Users\wolfg\Desktop\Django\tiliter_challenge>python manage.py makemigrations
Traceback (most recent call last):
  File "C:\Users\wolfg\Anaconda3\envs\movies\lib\site-packages\django\db\backends\utils.py", line 84, in _execute
    return self.cursor.execute(sql, params)
  File "C:\Users\wolfg\Anaconda3\envs\movies\lib\site-packages\django\db\backends\sqlite3\base.py", line 383, in execute
    return Database.Cursor.execute(self, query, params)
sqlite3.OperationalError: table movieapp_movie_class has no column named show_movie

The above exception was the direct cause of the following exception:

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\wolfg\Anaconda3\envs\movies\lib\site-packages\django\core\management\__init__.py", line 381, in execute_from_command_line
    utility.execute()
  File "C:\Users\wolfg\Anaconda3\envs\movies\lib\site-packages\django\core\management\__init__.py", line 375, in execute
    self.fetch_command(subcommand).run_from_argv(self.argv)
  File "C:\Users\wolfg\Anaconda3\envs\movies\lib\site-packages\django\core\management\base.py", line 323, in run_from_argv
    self.execute(*args, **cmd_options)
  File "C:\Users\wolfg\Anaconda3\envs\movies\lib\site-packages\django\core\management\base.py", line 361, in execute
    self.check()
  File "C:\Users\wolfg\Anaconda3\envs\movies\lib\site-packages\django\core\management\base.py", line 390, in check
    include_deployment_checks=include_deployment_checks,
  File "C:\Users\wolfg\Anaconda3\envs\movies\lib\site-packages\django\core\management\base.py", line 377, in _run_checks
    return checks.run_checks(**kwargs)
  File "C:\Users\wolfg\Anaconda3\envs\movies\lib\site-packages\django\core\checks\registry.py", line 72, in run_checks
    new_errors = check(app_configs=app_configs)
  File "C:\Users\wolfg\Anaconda3\envs\movies\lib\site-packages\django\core\checks\urls.py", line 13, in check_url_config
    return check_resolver(resolver)
  File "C:\Users\wolfg\Anaconda3\envs\movies\lib\site-packages\django\core\checks\urls.py", line 23, in check_resolver
    return check_method()
  File "C:\Users\wolfg\Anaconda3\envs\movies\lib\site-packages\django\urls\resolvers.py", line 398, in check
    for pattern in self.url_patterns:
  File "C:\Users\wolfg\Anaconda3\envs\movies\lib\site-packages\django\utils\functional.py", line 80, in __get__
    res = instance.__dict__[self.name] = self.func(instance)
  File "C:\Users\wolfg\Anaconda3\envs\movies\lib\site-packages\django\urls\resolvers.py", line 579, in url_patterns
    patterns = getattr(self.urlconf_module, "urlpatterns", self.urlconf_module)
  File "C:\Users\wolfg\Anaconda3\envs\movies\lib\site-packages\django\utils\functional.py", line 80, in __get__
    res = instance.__dict__[self.name] = self.func(instance)
  File "C:\Users\wolfg\Anaconda3\envs\movies\lib\site-packages\django\urls\resolvers.py", line 572, in urlconf_module
    return import_module(self.urlconf_name)
  File "C:\Users\wolfg\Anaconda3\envs\movies\lib\importlib\__init__.py", line 126, in import_module
    return _bootstrap._gcd_import(name[level:], package, level)
  File "<frozen importlib._bootstrap>", line 994, in _gcd_import
  File "<frozen importlib._bootstrap>", line 971, in _find_and_load
  File "<frozen importlib._bootstrap>", line 955, in _find_and_load_unlocked
  File "<frozen importlib._bootstrap>", line 665, in _load_unlocked
  File "<frozen importlib._bootstrap_external>", line 678, in exec_module
  File "<frozen importlib._bootstrap>", line 219, in _call_with_frames_removed
  File "C:\Users\wolfg\Desktop\Django\tiliter_challenge\tiliter_challenge\urls.py", line 18, in <module>
    from movieapp.views import movieView, search_movie
  File "C:\Users\wolfg\Desktop\Django\tiliter_challenge\movieapp\views.py", line 13, in <module>
    new_item.save()
  File "C:\Users\wolfg\Anaconda3\envs\movies\lib\site-packages\django\db\models\base.py", line 741, in save
    force_update=force_update, update_fields=update_fields)
  File "C:\Users\wolfg\Anaconda3\envs\movies\lib\site-packages\django\db\models\base.py", line 779, in save_base
    force_update, using, update_fields,
  File "C:\Users\wolfg\Anaconda3\envs\movies\lib\site-packages\django\db\models\base.py", line 870, in _save_table
    result = self._do_insert(cls._base_manager, using, fields, update_pk, raw)
  File "C:\Users\wolfg\Anaconda3\envs\movies\lib\site-packages\django\db\models\base.py", line 908, in _do_insert
    using=using, raw=raw)
  File "C:\Users\wolfg\Anaconda3\envs\movies\lib\site-packages\django\db\models\manager.py", line 82, in manager_method
    return getattr(self.get_queryset(), name)(*args, **kwargs)
  File "C:\Users\wolfg\Anaconda3\envs\movies\lib\site-packages\django\db\models\query.py", line 1186, in _insert
    return query.get_compiler(using=using).execute_sql(return_id)
  File "C:\Users\wolfg\Anaconda3\envs\movies\lib\site-packages\django\db\models\sql\compiler.py", line 1335, in execute_sql
    cursor.execute(sql, params)
  File "C:\Users\wolfg\Anaconda3\envs\movies\lib\site-packages\django\db\backends\utils.py", line 99, in execute
    return super().execute(sql, params)
  File "C:\Users\wolfg\Anaconda3\envs\movies\lib\site-packages\django\db\backends\utils.py", line 67, in execute
    return self._execute_with_wrappers(sql, params, many=False, executor=self._execute)
  File "C:\Users\wolfg\Anaconda3\envs\movies\lib\site-packages\django\db\backends\utils.py", line 76, in _execute_with_wrappers
    return executor(sql, params, many, context)
  File "C:\Users\wolfg\Anaconda3\envs\movies\lib\site-packages\django\db\backends\utils.py", line 84, in _execute
    return self.cursor.execute(sql, params)
  File "C:\Users\wolfg\Anaconda3\envs\movies\lib\site-packages\django\db\utils.py", line 89, in __exit__
    raise dj_exc_value.with_traceback(traceback) from exc_value
  File "C:\Users\wolfg\Anaconda3\envs\movies\lib\site-packages\django\db\backends\utils.py", line 84, in _execute
    return self.cursor.execute(sql, params)
  File "C:\Users\wolfg\Anaconda3\envs\movies\lib\site-packages\django\db\backends\sqlite3\base.py", line 383, in execute
    return Database.Cursor.execute(self, query, params)
django.db.utils.OperationalError: table movieapp_movie_class has no column named show_movie

0 个答案:

没有答案