未应用的迁移Django

时间:2020-03-02 22:48:08

标签: django

我遇到了Typeerror:预期的字符串或类似字节的对象,使我无法应用迁移。

如何找到此错误的来源。

产生的错误是: -/ admin / login /处的OperationalError没有这样的表:django_session -/ projects /中没有OperationalError,没有这样的列:使用ForeignKey时,为projects_project.chantier_id。

创建一个新项目的视图:

views.py

def create_project(request):
        form = ProjectForm(request.POST or None, request.FILES or None)
        if form.is_valid():
            project = form.save(commit=False)
            project.save()
            return render(request, 'projects/detail.html', {'project': project})
        context = {
            "form": form,
        }
        return render(request, 'projects/create_project.html', context)

我的模型:

class Project(models.Model):

    PROJECT_TYPE = (      
        (0, 'Service'),
        (1, 'Remedials'),
        (2, 'Project'),
        (3, 'Call Out'),
        (4, 'Breakdown'),
        (5, 'One Off'),
        (6, 'Others'),
        )
    user = models.ForeignKey(User, default=1, on_delete=models.CASCADE)
    type = models.IntegerField(choices=PROJECT_TYPE,default=1)
    chantier = models.ForeignKey(Chantier, default=1, on_delete=models.CASCADE)

这是错误消息。

WARNINGS:
?: (2_0.W001) Your URL pattern '(?P<project_id>[0-9]+)/render/pdf/$' [name='Pdf'] has a route that contains '(?P<', begins with a '^', or ends with a '$'. This was likely an oversight when migrating to django.urls.path().
Operations to perform:
  Apply all migrations: projects
Running migrations:
  Applying projects.0008_auto_20200223_0126...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\servi\AppData\Local\Programs\Python\Python37-32\lib\site-packages\django\core\management\__init__.py", line 381, in execute_from_command_line
    utility.execute()
  File "C:\Users\servi\AppData\Local\Programs\Python\Python37-32\lib\site-packages\django\core\management\__init__.py", line 375, in execute
    self.fetch_command(subcommand).run_from_argv(self.argv)
  File "C:\Users\servi\AppData\Local\Programs\Python\Python37-32\lib\site-packages\django\core\management\base.py", line 323, in run_from_argv
    self.execute(*args, **cmd_options)
  File "C:\Users\servi\AppData\Local\Programs\Python\Python37-32\lib\site-packages\django\core\management\base.py", line 364, in execute
    output = self.handle(*args, **options)
  File "C:\Users\servi\AppData\Local\Programs\Python\Python37-32\lib\site-packages\django\core\management\base.py", line 83, in wrapped
    res = handle_func(*args, **kwargs)
  File "C:\Users\servi\AppData\Local\Programs\Python\Python37-32\lib\site-packages\django\core\management\commands\migrate.py", line 234, in handle
    fake_initial=fake_initial,
  File "C:\Users\servi\AppData\Local\Programs\Python\Python37-32\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\servi\AppData\Local\Programs\Python\Python37-32\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\servi\AppData\Local\Programs\Python\Python37-32\lib\site-packages\django\db\migrations\executor.py", line 245, in apply_migration
    state = migration.apply(state, schema_editor)
  File "C:\Users\servi\AppData\Local\Programs\Python\Python37-32\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\servi\AppData\Local\Programs\Python\Python37-32\lib\site-packages\django\db\migrations\operations\fields.py", line 112, in database_forwards
    field,
  File "C:\Users\servi\AppData\Local\Programs\Python\Python37-32\lib\site-packages\django\db\backends\sqlite3\schema.py", line 327, in add_field
    self._remake_table(model, create_field=field)
  File "C:\Users\servi\AppData\Local\Programs\Python\Python37-32\lib\site-packages\django\db\backends\sqlite3\schema.py", line 188, in _remake_table
    self.effective_default(create_field)
  File "C:\Users\servi\AppData\Local\Programs\Python\Python37-32\lib\site-packages\django\db\backends\base\schema.py", line 233, in effective_default
    return field.get_db_prep_save(self._effective_default(field), self.connection)
  File "C:\Users\servi\AppData\Local\Programs\Python\Python37-32\lib\site-packages\django\db\models\fields\__init__.py", line 789, in get_db_prep_save
    return self.get_db_prep_value(value, connection=connection, prepared=False)
  File "C:\Users\servi\AppData\Local\Programs\Python\Python37-32\lib\site-packages\django\db\models\fields\__init__.py", line 1273, in get_db_prep_value
    value = self.get_prep_value(value)
  File "C:\Users\servi\AppData\Local\Programs\Python\Python37-32\lib\site-packages\django\db\models\fields\__init__.py", line 1268, in get_prep_value
    return self.to_python(value)
  File "C:\Users\servi\AppData\Local\Programs\Python\Python37-32\lib\site-packages\django\db\models\fields\__init__.py", line 1230, in to_python
    parsed = parse_date(value)
  File "C:\Users\servi\AppData\Local\Programs\Python\Python37-32\lib\site-packages\django\utils\dateparse.py", line 74, in parse_date
    match = date_re.match(value)
TypeError: expected string or bytes-like object

0 个答案:

没有答案