diff --git a/gns3server/api/routes/controller/images.py b/gns3server/api/routes/controller/images.py index 46e0f4a1..6083e906 100644 --- a/gns3server/api/routes/controller/images.py +++ b/gns3server/api/routes/controller/images.py @@ -124,7 +124,7 @@ async def delete_image( if not image: raise ControllerNotFoundError(f"Image '{image_path}' not found") - if await images_repo.get_image_templates(image.id): + if await images_repo.get_image_templates(image.image_id): raise ControllerError(f"Image '{image_path}' is used by one or more templates") try: diff --git a/gns3server/db/models/images.py b/gns3server/db/models/images.py index 9db3a682..175ab278 100644 --- a/gns3server/db/models/images.py +++ b/gns3server/db/models/images.py @@ -15,7 +15,7 @@ # You should have received a copy of the GNU General Public License # along with this program. If not, see . -from sqlalchemy import Table, Column, String, ForeignKey, BigInteger +from sqlalchemy import Table, Column, String, ForeignKey, BigInteger, Integer from sqlalchemy.orm import relationship from .base import Base, BaseTable, GUID @@ -24,7 +24,7 @@ from .base import Base, BaseTable, GUID image_template_link = Table( "images_templates_link", Base.metadata, - Column("image_id", BigInteger, ForeignKey("images.image_id", ondelete="CASCADE")), + Column("image_id", Integer, ForeignKey("images.image_id", ondelete="CASCADE")), Column("template_id", GUID, ForeignKey("templates.template_id", ondelete="CASCADE")) ) @@ -33,7 +33,7 @@ class Image(BaseTable): __tablename__ = "images" - image_id = Column(BigInteger, primary_key=True, autoincrement=True) + image_id = Column(Integer, primary_key=True, autoincrement=True) filename = Column(String, index=True) path = Column(String, unique=True) image_type = Column(String) diff --git a/gns3server/db/repositories/images.py b/gns3server/db/repositories/images.py index b13c5fc3..17bf4c71 100644 --- a/gns3server/db/repositories/images.py +++ b/gns3server/db/repositories/images.py @@ -75,7 +75,7 @@ class ImagesRepository(BaseRepository): query = select(models.Template).\ join(models.Template.images).\ - filter(models.Image.id == image_id) + filter(models.Image.image_id == image_id) result = await self._db_session.execute(query) return result.scalars().all() @@ -86,7 +86,7 @@ class ImagesRepository(BaseRepository): """ db_image = models.Image( - id=None, + image_id=None, filename=image_name, image_type=image_type, image_size=image_size,