如何解决web2py中出现的重复列名错误



我在pythonanywhere上运行web2py。当db.py文件运行时,我开始得到一个重复的列名错误。我试过从备份中恢复数据库,也试过删除表并将其添加回来,但没有成功。此时,我完全被锁在应用程序之外了。

我已经尝试删除表中除最后一个字段外的所有字段,但随后问题出现在下一个表中。

我想知道web2py是否使用了需要清除的缓存。

下面是db.py文件的相关部分:

db.define_table('library',
Field('title', 'string'),
Field('created','datetime'),
Field('duration','float'),
Field('error_message','string'),
Field('external_id','string'),
Field('hosting_type','string'),
Field('source_id','string', unique = True),
Field('last_modified','datetime'),
Field('media_type','string'),
Field('mime_type','string'),
Field('relationships','string'),
Field('source_schema','string'),
Field('source_url','string'),
Field('status','string'),
Field('trim_in_point','string'),
Field('trim_out_point','string'),
Field('source_type','string'),
Field('poster','string'),
Field('background_poster_filename','string'),
Field('background_poster','upload', required=False, requires = IS_EMPTY_OR(IS_IMAGE(extensions=('png', 'jpg', 'jpeg'), maxsize=(1920, 1080)))),
Field('sources','list:string',length = 4096),
Field('tracks','string'),
singular="Library",
plural="Library"
)

错误提示:

Ticket ID
67.0.14.100.2022-06-23.16-49-09.ecf75fd3-1bb4-4f76-b557-95e072c6681f
<class 'gluon.contrib.pymysql.err.InternalError'> (1060, "Duplicate column name 'title'")
Version
web2py™ Version 2.21.1-stable+timestamp.2020.11.28.04.10.44
Python  Python 3.7.10: /usr/local/bin/uwsgi (prefix: /home/ghdev/.virtualenvs/ghdevvirtualenv)
Traceback
Traceback (most recent call last):
File "/home/ghdev/web2py/gluon/restricted.py", line 219, in restricted
exec(ccode, environment)
File "/home/ghdev/web2py/applications/ghrokucms/models/db.py", line 283, in <module>
plural="Library"
File "/home/ghdev/web2py/gluon/packages/dal/pydal/base.py", line 660, in define_table
table = self.lazy_define_table(tablename, *fields, **kwargs)
File "/home/ghdev/web2py/gluon/packages/dal/pydal/base.py", line 701, in lazy_define_table
polymodel=polymodel,
File "/home/ghdev/web2py/gluon/packages/dal/pydal/adapters/base.py", line 920, in create_table
return self.migrator.create_table(*args, **kwargs)
File "/home/ghdev/web2py/gluon/packages/dal/pydal/migrator.py", line 376, in create_table
fake_migrate=fake_migrate,
File "/home/ghdev/web2py/gluon/packages/dal/pydal/migrator.py", line 544, in migrate_table
self.adapter.execute(sub_query)
File "/home/ghdev/web2py/gluon/packages/dal/pydal/adapters/__init__.py", line 69, in wrap
return f(*args, **kwargs)
File "/home/ghdev/web2py/gluon/packages/dal/pydal/adapters/base.py", line 468, in execute
rv = self.cursor.execute(command, *args[1:], **kwargs)
File "/home/ghdev/web2py/gluon/contrib/pymysql/cursors.py", line 166, in execute
result = self._query(query)
File "/home/ghdev/web2py/gluon/contrib/pymysql/cursors.py", line 322, in _query
conn.query(q)
File "/home/ghdev/web2py/gluon/contrib/pymysql/connections.py", line 835, in query
self._affected_rows = self._read_query_result(unbuffered=unbuffered)
File "/home/ghdev/web2py/gluon/contrib/pymysql/connections.py", line 1019, in _read_query_result
result.read()
File "/home/ghdev/web2py/gluon/contrib/pymysql/connections.py", line 1302, in read
first_packet = self.connection._read_packet()
File "/home/ghdev/web2py/gluon/contrib/pymysql/connections.py", line 981, in _read_packet
packet.check_error()
File "/home/ghdev/web2py/gluon/contrib/pymysql/connections.py", line 393, in check_error
err.raise_mysql_exception(self._data)
File "/home/ghdev/web2py/gluon/contrib/pymysql/err.py", line 107, in raise_mysql_exception
raise errorclass(errno, errval)
gluon.contrib.pymysql.err.InternalError: (1060, "Duplicate column name 'title'")

我不知道如何解决这个问题。如有任何帮助,我将不胜感激。

谢谢。

我解决了这个问题。除了删除表之外,我还需要删除web2py数据库目录中的相关文件。然后我必须手动将表添加回mySql数据库。

解决。

相关内容

最新更新