运行“Django manage.py migrate”命令后出现此错误

如何解决运行“Django manage.py migrate”命令后出现此错误

这是我得到的所有错误
PS E:\funds\Restaurant\restaurant> python manage.py makemigrations 您是否将 menu.Order 模型重命名为 Orders? [是/否] n “菜单”的迁移: 菜单\迁移\0003_auto_20210417_2034.py - 创建模型订单 - 删除模型订单

    PS E:\funds\Restaurant\restaurant> python manage.py migrate  
    Operations to perform:
      Apply all migrations: admin,auth,contenttypes,menu,sessions
    Running migrations:
      Applying menu.0003_auto_20210417_2034...Traceback (most recent call last):
      File "C:\Users\tejas\AppData\Local\Programs\Python\python39\lib\site-packages\django\db\backends\utils.py",line 84,in _execute
        return self.cursor.execute(sql)
      File "C:\Users\tejas\AppData\Local\Programs\Python\python39\lib\site-packages\django\db\backends\sqlite3\base.py",line 394,in execute
        return Database.Cursor.execute(self,query)
    sqlite3.OperationalError: table "menu_orders" already exists
    
    The above exception was the direct cause of the following exception:
    
    Traceback (most recent call last):
      File "E:\funds\Restaurant\restaurant\manage.py",line 21,in <module>
        main()
      File "E:\funds\Restaurant\restaurant\manage.py",line 17,in main
        execute_from_command_line(sys.argv)
      File "C:\Users\tejas\AppData\Local\Programs\Python\python39\lib\site-packages\django\core\management\__init__.py",line 401,in execute_from_command_line
        utility.execute()
      File "C:\Users\tejas\AppData\Local\Programs\Python\python39\lib\site-packages\django\core\management\__init__.py",line 395,in execute
        self.fetch_command(subcommand).run_from_argv(self.argv)
      File "C:\Users\tejas\AppData\Local\Programs\Python\python39\lib\site-packages\django\core\management\base.py",line 328,in run_from_argv
        self.execute(*args,**cmd_options)
      File "C:\Users\tejas\AppData\Local\Programs\Python\python39\lib\site-packages\django\core\management\base.py",line 369,in execute
        output = self.handle(*args,**options)
      File "C:\Users\tejas\AppData\Local\Programs\Python\python39\lib\site-packages\django\core\management\base.py",line 83,in wrapped
        res = handle_func(*args,**kwargs)
      File "C:\Users\tejas\AppData\Local\Programs\Python\python39\lib\site-packages\django\core\management\commands\migrate.py",line 231,in handle
        post_migrate_state = executor.migrate(
      File "C:\Users\tejas\AppData\Local\Programs\Python\python39\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\tejas\AppData\Local\Programs\Python\python39\lib\site-packages\django\db\migrations\executor.py",line 147,in _migrate_all_forwards
        state = self.apply_migration(state,migration,line 245,in apply_migration
        state = migration.apply(state,schema_editor)
      File "C:\Users\tejas\AppData\Local\Programs\Python\python39\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\tejas\AppData\Local\Programs\Python\python39\lib\site-packages\django\db\migrations\operations\models.py",line 92,in database_forwards
        schema_editor.create_model(model)
      File "C:\Users\tejas\AppData\Local\Programs\Python\python39\lib\site-packages\django\db\backends\base\schema.py",line 324,in create_model
        self.execute(sql,params or None)
      File "C:\Users\tejas\AppData\Local\Programs\Python\python39\lib\site-packages\django\db\backends\base\schema.py",line 142,in execute
        cursor.execute(sql,params)
      File "C:\Users\tejas\AppData\Local\Programs\Python\python39\lib\site-packages\django\db\backends\utils.py",line 100,in execute
        return super().execute(sql,line 68,in execute
        return self._execute_with_wrappers(sql,params,many=False,executor=self._execute)
      File "C:\Users\tejas\AppData\Local\Programs\Python\python39\lib\site-packages\django\db\backends\utils.py",line 77,in _execute_with_wrappers
        return executor(sql,many,context)
      File "C:\Users\tejas\AppData\Local\Programs\Python\python39\lib\site-packages\django\db\backends\utils.py",line 86,in _execute
        return self.cursor.execute(sql,params)
      File "C:\Users\tejas\AppData\Local\Programs\Python\python39\lib\site-packages\django\db\utils.py",line 90,in __exit__
        raise dj_exc_value.with_traceback(traceback) from exc_value
      File "C:\Users\tejas\AppData\Local\Programs\Python\python39\lib\site-packages\django\db\backends\utils.py",query)
    django.db.utils.OperationalError: table "menu_orders" already exists

由 Django 3.0.11 于 2021-04-17 15:04 生成

0003_auto_20210417_2034.py

from django.db import migrations,models


class Migration(migrations.Migration):

    dependencies = [
        ('menu','0002_auto_20210409_1242'),]

    operations = [
        migrations.CreateModel(
            name='Orders',fields=[
                ('order_id',models.AutoField(primary_key=True,serialize=False)),('items_json',models.CharField(max_length=5000)),('name',models.CharField(max_length=90)),('email',models.CharField(max_length=111)),('address',('city',('state',('zip_code',('phone',models.CharField(default='',max_length=111)),],),migrations.DeleteModel(
            name='Order',]

models.py

from django.db import models

# Create your models here.
class foodItems(models.Model):
    foodItems_id = models.AutoField
    foodItems_name = models.CharField(max_length=50)
    category = models.CharField(max_length=50,default="")
    price = models.IntegerField(default=0)
    image = models.ImageField(upload_to='menu/images',default="")

    def __str__(self):
        return self.foodItems_name


class Contact(models.Model):
    msg_id = models.AutoField(primary_key=True)
    name = models.CharField(max_length=50)
    email = models.CharField(max_length=70,default="")
    phone = models.CharField(max_length=70,default="")
    desc = models.CharField(max_length=500,default="")


    def __str__(self):
        return self.name

class Orders(models.Model):
    order_id = models.AutoField(primary_key=True)
    items_json = models.CharField(max_length=5000)
    name = models.CharField(max_length=90)
    email = models.CharField(max_length=111)
    address = models.CharField(max_length=111)
    city = models.CharField(max_length=111)
    state = models.CharField(max_length=111)
    zip_code = models.CharField(max_length=111)
    phone = models.CharField(max_length=111,default="")

class OrderUpdate(models.Model):
    update_id  = models.AutoField(primary_key=True)
    order_id = models.IntegerField(default="")
    update_desc = models.CharField(max_length=5000)
    timestamp = models.DateField(auto_Now_add=True)

    def __str__(self):
        return self.update_desc[0:7] + "..."

0001_initial.py

# Generated by Django 3.0.11 on 2021-04-08 05:18

from django.db import migrations,models


class Migration(migrations.Migration):

    initial = True

    dependencies = [
    ]

    operations = [
        migrations.CreateModel(
            name='Contact',fields=[
                ('msg_id',models.CharField(max_length=50)),max_length=70)),('desc',max_length=500)),migrations.CreateModel(
            name='foodItems',fields=[
                ('id',models.AutoField(auto_created=True,primary_key=True,serialize=False,verbose_name='ID')),('foodItems_name',('category',max_length=50)),('subcategory',('price',models.IntegerField(default=0)),models.CharField(max_length=300)),('pub_date',models.DateField()),('image',models.ImageField(default='',upload_to='menu/images')),migrations.CreateModel(
            name='Order',migrations.CreateModel(
            name='OrderUpdate',fields=[
                ('update_id',('order_id',models.IntegerField(default='')),('update_desc',('timestamp',models.DateField(auto_Now_add=True)),]

版权声明:本文内容由互联网用户自发贡献,该文观点与技术仅代表作者本人。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌侵权/违法违规的内容, 请发送邮件至 dio@foxmail.com 举报,一经查实,本站将立刻删除。

相关推荐


Selenium Web驱动程序和Java。元素在(x,y)点处不可单击。其他元素将获得点击?
Python-如何使用点“。” 访问字典成员?
Java 字符串是不可变的。到底是什么意思?
Java中的“ final”关键字如何工作?(我仍然可以修改对象。)
“loop:”在Java代码中。这是什么,为什么要编译?
java.lang.ClassNotFoundException:sun.jdbc.odbc.JdbcOdbcDriver发生异常。为什么?
这是用Java进行XML解析的最佳库。
Java的PriorityQueue的内置迭代器不会以任何特定顺序遍历数据结构。为什么?
如何在Java中聆听按键时移动图像。
Java“Program to an interface”。这是什么意思?
Java在半透明框架/面板/组件上重新绘画。
Java“ Class.forName()”和“ Class.forName()。newInstance()”之间有什么区别?
在此环境中不提供编译器。也许是在JRE而不是JDK上运行?
Java用相同的方法在一个类中实现两个接口。哪种接口方法被覆盖?
Java 什么是Runtime.getRuntime()。totalMemory()和freeMemory()?
java.library.path中的java.lang.UnsatisfiedLinkError否*****。dll
JavaFX“位置是必需的。” 即使在同一包装中
Java 导入两个具有相同名称的类。怎么处理?
Java 是否应该在HttpServletResponse.getOutputStream()/。getWriter()上调用.close()?
Java RegEx元字符(。)和普通点?