for s in sizes: Inventory.objects.create(count=100,goods=good, color=c, size=s)TypeError: Inventory() got an unexpected keyword argument 'size'如何修正
时间: 2023-06-20 09:04:37 浏览: 68
在 Inventory 模型中添加一个 size 字段,或者检查是否该字段的名称写错了,应该与模型中的字段名称一致。如果 Inventory 模型中没有 size 字段,您需要运行数据库迁移以添加该字段。您可以使用以下命令运行数据库迁移:
```
python manage.py makemigrations
python manage.py migrate
```
这将根据您的模型更改创建数据库迁移并将其应用于数据库。
相关问题
>>> import sys ... import arcpy ... import string ... ... reload(sys) ... sys.setdefaultencoding('utf-8') ... ... try: ... workspace = 'C:\Users\Administrator\Desktop\\qwe' ... outdb = 'C:\Users\Administrator\Desktop\\lutian.mdb' ... arcpy.env.workspace = workspace ... files = arcpy.ListFiles('*.*db') ... arcpy.env.workspace = outdb ... fcs = arcpy.ListFeatureClasses() ... fcs = fcs + arcpy.ListTables() ... dss = arcpy.ListDatasets() ... ... for File in files: ... for fc in fcs: ... arcpy.Append_management(workspace + '\\' + File + '\\' + fc, outdb + '\\' + fc) ... ... for ds in dss: ... fcs1 = arcpy.ListFeatureClasses(feature_dataset = ds) ... for fc1 in fcs1: ... arcpy.Append_management(workspace + '\\' + File + '\\' + ds + '\\' + fc1, outdb + '\\' + ds + '\\' + fc1) ... ... except arcpy.ExecuteError: ... print arcpy.GetMessages() ... Runtime error Traceback (most recent call last): File "<string>", line 15, in <module> TypeError: unsupported operand type(s) for +: 'NoneType' and 'NoneType',根据错误完善此代码
这段代码中出现了两个问题,一个是缩进问题,一个是字符串连接问题。以下是修改后的代码。
```python
import sys
import arcpy
import string
reload(sys)
sys.setdefaultencoding('utf-8')
try:
workspace = 'C:\\Users\\Administrator\\Desktop\\qwe'
outdb = 'C:\\Users\\Administrator\\Desktop\\lutian.mdb'
arcpy.env.workspace = workspace
files = arcpy.ListFiles('*.*db')
arcpy.env.workspace = outdb
fcs = arcpy.ListFeatureClasses()
fcs = fcs + arcpy.ListTables()
dss = arcpy.ListDatasets()
for File in files:
for fc in fcs:
arcpy.Append_management(workspace + '\\' + File + '\\' + fc, outdb + '\\' + fc)
for ds in dss:
fcs1 = arcpy.ListFeatureClasses(feature_dataset = ds)
for fc1 in fcs1:
arcpy.Append_management(workspace + '\\' + File + '\\' + ds + '\\' + fc1, outdb + '\\' + ds + '\\' + fc1)
except arcpy.ExecuteError:
print(arcpy.GetMessages())
```
修改后的代码中,缩进问题已经被修复,并且修改了字符串连接方式,使用双反斜杠来转义路径中的反斜杠,防止出现字符串连接问题。另外,在except语句中,使用了print函数来输出错误信息。
from openpyxl import load_workbook, Workbook from openpyxl.styles import PatternFill class ExcelMerger: def __init__(self, input_path, output_path): self.input_path = input_path self.output_path = output_path self.workbook = Workbook() self.sheet = self.workbook.active self.fill = PatternFill(fill_type='solid', start_color='FFFFFF', end_color='FFFFFF') self.row_index = 1 def merge(self): for filename in os.listdir(self.input_path): if not filename.endswith('.xlsx'): continue filepath = os.path.join(self.input_path, filename) workbook = load_workbook(filepath, data_only=True) if '功能点拆分表' not in workbook.sheetnames: continue sheet = workbook['功能点拆分表'] for row in sheet.rows: self.sheet.row_dimensions[self.row_index].height = sheet.row_dimensions[row[0].row].height for cell in row: if cell.value is not None: self.sheet.cell(row=self.row_index, column=cell.column, value=cell.value) self.sheet.cell(row=self.row_index, column=cell.column).fill = cell.fill else: self.sheet.cell(row=self.row_index, column=cell.column).fill = self.fill self.row_index += 1 self.workbook.save(self.output_path)上述修改后的代码仍然出现TypeError: unhashable type: 'StyleProxy'的错误,怎么解决
这个问题通常是由于样式对象(Style)是不可哈希的导致的。在这种情况下,你需要将样式对象转换为可哈希的对象,或者使用其他数据结构来代替字典。
你可以尝试将样式对象转换为字符串,然后将字符串作为键来使用。例如,可以使用`str(style)`来获取样式对象的字符串表示形式,并将其用作字典的键,如下所示:
```
cell_style = {}
...
if cell.has_style:
cell_style[cell.coordinate] = str(cell.style)
...
```
这样就可以避免`TypeError: unhashable type: 'StyleProxy'`错误。
当然,这只是一种解决方案,具体如何修改代码需要根据具体情况而定。
阅读全文