diff --git a/backend/src/baserow/contrib/database/migrations/0170_update_password_tsv_fields.py b/backend/src/baserow/contrib/database/migrations/0170_update_password_tsv_fields.py index 154a1061fa..5669b60a99 100644 --- a/backend/src/baserow/contrib/database/migrations/0170_update_password_tsv_fields.py +++ b/backend/src/baserow/contrib/database/migrations/0170_update_password_tsv_fields.py @@ -32,4 +32,4 @@ class Migration(migrations.Migration): ("database", "0169_alter_galleryview_card_cover_image_field"), ] - operations = [migrations.RunSQL(update_password_tsv_index)] + operations = [migrations.RunSQL(update_password_tsv_index, migrations.RunSQL.noop)] diff --git a/backend/src/baserow/core/pgvector.py b/backend/src/baserow/core/pgvector.py index d0678a6475..890c52e7f5 100644 --- a/backend/src/baserow/core/pgvector.py +++ b/backend/src/baserow/core/pgvector.py @@ -45,9 +45,6 @@ def try_enable_pgvector() -> bool: :return: True if the extension is now enabled, False otherwise. """ - if is_pgvector_enabled(): - return True - try: with connection.cursor() as cursor: cursor.execute("CREATE EXTENSION IF NOT EXISTS vector;") @@ -321,6 +318,15 @@ def try_migrate_vector_fields(sender, **kwargs): previously disabled, so that the field and index can be created later. """ + # Check if the ContentType for SchemaOperation exists. If not, it means the + # core migrations haven't fully run yet (e.g., in migration tests with a + # separate database), so we skip the vector field migration. + if not ContentType.objects.filter( + app_label="core", model="schemaoperation" + ).exists(): + print("skipped (SchemaOperation content type not ready).") + return + was_enabled = is_pgvector_enabled() pgvector_enabled = try_enable_pgvector() diff --git a/backend/src/baserow/test_utils/pytest_conftest.py b/backend/src/baserow/test_utils/pytest_conftest.py index 01fabb1bad..de8f5b142c 100755 --- a/backend/src/baserow/test_utils/pytest_conftest.py +++ b/backend/src/baserow/test_utils/pytest_conftest.py @@ -828,6 +828,14 @@ def second_separate_database_for_migrations( _set_suffix_to_test_databases(suffix) with django_db_blocker.unblock(): + # Clear ContentType cache before setting up the second database. + # The cache may contain IDs from the first test database, which would + # cause foreign key violations when post_migrate signals try to create + # records referencing ContentTypes in the new database. + from django.contrib.contenttypes.models import ContentType + + ContentType.objects.clear_cache() + db_cfg = setup_databases( verbosity=request.config.option.verbose, interactive=False, diff --git a/enterprise/backend/src/baserow_enterprise/migrations/0044_migrate_app_labels.py b/enterprise/backend/src/baserow_enterprise/migrations/0044_migrate_app_labels.py index 0d0226069f..e8c28d1057 100644 --- a/enterprise/backend/src/baserow_enterprise/migrations/0044_migrate_app_labels.py +++ b/enterprise/backend/src/baserow_enterprise/migrations/0044_migrate_app_labels.py @@ -29,5 +29,5 @@ class Migration(migrations.Migration): ] operations = [ - migrations.RunPython(migrate_app_labels), + migrations.RunPython(migrate_app_labels, migrations.RunPython.noop), ]