forked from openlp/openlp
SQLite doesn't support changing a primary key
This commit is contained in:
parent
d62cd37db4
commit
cc635e9b96
@ -528,7 +528,7 @@ class EditSongForm(QtGui.QDialog, Ui_EditSongDialog, RegistryProperties):
|
|||||||
elif item > 0:
|
elif item > 0:
|
||||||
item_id = (self.authors_combo_box.itemData(item))
|
item_id = (self.authors_combo_box.itemData(item))
|
||||||
author = self.manager.get_object(Author, item_id)
|
author = self.manager.get_object(Author, item_id)
|
||||||
if self.authors_list_view.findItems(str(author.display_name), QtCore.Qt.MatchExactly):
|
if self.authors_list_view.findItems(author.get_display_name(author_type), QtCore.Qt.MatchExactly):
|
||||||
critical_error_message_box(
|
critical_error_message_box(
|
||||||
message=translate('SongsPlugin.EditSongForm', 'This author is already in the list.'))
|
message=translate('SongsPlugin.EditSongForm', 'This author is already in the list.'))
|
||||||
else:
|
else:
|
||||||
|
@ -32,7 +32,7 @@ backend for the Songs plugin
|
|||||||
"""
|
"""
|
||||||
import logging
|
import logging
|
||||||
|
|
||||||
from sqlalchemy import Column, types
|
from sqlalchemy import Column, ForeignKey, types
|
||||||
from sqlalchemy.exc import OperationalError
|
from sqlalchemy.exc import OperationalError
|
||||||
from sqlalchemy.sql.expression import func, false, null, text
|
from sqlalchemy.sql.expression import func, false, null, text
|
||||||
|
|
||||||
@ -106,8 +106,15 @@ def upgrade_4(session, metadata):
|
|||||||
This upgrade adds a column for author type to the authors_songs table
|
This upgrade adds a column for author type to the authors_songs table
|
||||||
"""
|
"""
|
||||||
try:
|
try:
|
||||||
|
# Since SQLite doesn't support changing the primary key of a table, we need to recreate the table
|
||||||
|
# and copy the old values
|
||||||
op = get_upgrade_op(session)
|
op = get_upgrade_op(session)
|
||||||
op.add_column('authors_songs', Column('author_type', types.String(), primary_key=True,
|
op.create_table('authors_songs_tmp',
|
||||||
nullable=False, server_default=text('""')))
|
Column('author_id', types.Integer(), ForeignKey('authors.id'), primary_key=True),
|
||||||
|
Column('song_id', types.Integer(), ForeignKey('songs.id'), primary_key=True),
|
||||||
|
Column('author_type', types.String(), primary_key=True, nullable=False, server_default=text('""')))
|
||||||
|
op.execute('INSERT INTO authors_songs_tmp SELECT author_id, song_id, "" FROM authors_songs')
|
||||||
|
op.drop_table('authors_songs')
|
||||||
|
op.rename_table('authors_songs_tmp', 'authors_songs')
|
||||||
except OperationalError:
|
except OperationalError:
|
||||||
log.info('Upgrade 4 has already been run')
|
log.info('Upgrade 4 has already been run')
|
||||||
|
Loading…
Reference in New Issue
Block a user