Python 我在运行“后出现此错误”;Django manage.py migrate“;命令
这就是我得到的所有错误:Python 我在运行“后出现此错误”;Django manage.py migrate“;命令,python,django,sqlite,django-models,django-migrations,Python,Django,Sqlite,Django Models,Django Migrations,这就是我得到的所有错误: PS E:\funds\Restaurant\Restaurant>python manage.py makemigrations 您是否将菜单.订单型号重命名为订单?[是/否]N “菜单”的迁移: 菜单\migrations\0003\u auto\u 20210417\u 2034.py -创建模型订单 -删除模型订单 PS E:\funds\Restaurant\restaurant> python manage.py migrate O
PS E:\funds\Restaurant\Restaurant>python manage.py makemigrations 您是否将菜单.订单型号重命名为订单?[是/否]N “菜单”的迁移: 菜单\migrations\0003\u auto\u 20210417\u 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, fake=fake, fake_initial=fake_initial)
File "C:\Users\tejas\AppData\Local\Programs\Python\Python39\lib\site-packages\django\db\migrations\executor.py", 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, params)
File "C:\Users\tejas\AppData\Local\Programs\Python\Python39\lib\site-packages\django\db\backends\utils.py", 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, params, 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", 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)
django.db.utils.OperationalError: table "menu_orders" already exists
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_首字母.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.AutoField(primary_key=True, serialize=False)),
('name', models.CharField(max_length=50)),
('email', models.CharField(default='', max_length=70)),
('phone', models.CharField(default='', max_length=70)),
('desc', models.CharField(default='', max_length=500)),
],
),
migrations.CreateModel(
name='foodItems',
fields=[
('id', models.AutoField(auto_created=True, primary_key=True, serialize=False, verbose_name='ID')),
('foodItems_name', models.CharField(max_length=50)),
('category', models.CharField(default='', max_length=50)),
('subcategory', models.CharField(default='', max_length=50)),
('price', models.IntegerField(default=0)),
('desc', models.CharField(max_length=300)),
('pub_date', models.DateField()),
('image', models.ImageField(default='', upload_to='menu/images')),
],
),
migrations.CreateModel(
name='Order',
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', 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(default='', max_length=111)),
],
),
migrations.CreateModel(
name='OrderUpdate',
fields=[
('update_id', models.AutoField(primary_key=True, serialize=False)),
('order_id', models.IntegerField(default='')),
('update_desc', models.CharField(max_length=5000)),
('timestamp', models.DateField(auto_now_add=True)),
],
),
]
请分享更改前后的模型和迁移文件以及0003_auto_20210417_2034.py我添加了您所说的文件,我认为您把迁移搞砸了。您能检查一下在三个迁移文件中是否已经有“migrations.CreateModel(name='Orders',”吗?我现在又添加了一个迁移文件:0001_initial.py=这里是migrations.CreateModel(name='Order')不是“Orders”写的.那么我现在该怎么办?为什么你们有两种订单模型?你们是将订单模型重命名为订单还是其他方式?
# 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.AutoField(primary_key=True, serialize=False)),
('name', models.CharField(max_length=50)),
('email', models.CharField(default='', max_length=70)),
('phone', models.CharField(default='', max_length=70)),
('desc', models.CharField(default='', max_length=500)),
],
),
migrations.CreateModel(
name='foodItems',
fields=[
('id', models.AutoField(auto_created=True, primary_key=True, serialize=False, verbose_name='ID')),
('foodItems_name', models.CharField(max_length=50)),
('category', models.CharField(default='', max_length=50)),
('subcategory', models.CharField(default='', max_length=50)),
('price', models.IntegerField(default=0)),
('desc', models.CharField(max_length=300)),
('pub_date', models.DateField()),
('image', models.ImageField(default='', upload_to='menu/images')),
],
),
migrations.CreateModel(
name='Order',
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', 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(default='', max_length=111)),
],
),
migrations.CreateModel(
name='OrderUpdate',
fields=[
('update_id', models.AutoField(primary_key=True, serialize=False)),
('order_id', models.IntegerField(default='')),
('update_desc', models.CharField(max_length=5000)),
('timestamp', models.DateField(auto_now_add=True)),
],
),
]