'swift run App migrate' produces error

With this migration:

import Foundation
import Fluent

struct CreateCoursesTableMigration: AsyncMigration {
    
    func prepare(on database: Database) async throws {
        //create table
        try await database.schema("courses")
            .id()
            .field("Title", .string, .required)
            .create()
        
    }
    
    func revert(on database: Database) async throws {
        //delet table
        try await database.schema("courses")
            .delete()
    }
}

Registered in the configure file:

import Vapor
import Fluent
import FluentPostgresDriver

// configures your application
public func configure(_ app: Application) async throws {
    // uncomment to serve files from /Public folder
    // app.middleware.use(FileMiddleware(publicDirectory: app.directory.publicDirectory))
    
    // register database
    app.databases.use(.postgres(configuration: try postgresConfiguration), as: .psql)
    
    // register migrations
    app.migrations.add(CreateCoursesTableMigration())

    
    // register routes
    try routes(app)
}

This compiles without error, but when running ''swift run App migrate', it produces the following error:

error: terminated(1): /usr/bin/xcrun --sdk macosx --show-sdk-platform-path output:
xcrun: error: unable to lookup item 'PlatformPath' from command line tools installation
xcrun: error: unable to lookup item 'PlatformPath' in SDK '/Library/Developer/CommandLineTools/SDKs/MacOSX.sdk'

How can I fix this? Thanks!

I believe Homebrew has screwed up your command line.

Run

sudo xcode-select -s /Applications/Xcode.app

Or wherever you've installed Xcode

2 Likes

This fixed it. Thank you @0xTim!

1 Like