Skip to content

Adding attribute name for BelongsToMany sometimes causes migration error #756

@LorenzoPapi

Description

@LorenzoPapi
  • Laravel Version: 12.34.0
  • PHP Version: 8.4.13
  • Blueprint Version: 2.12.0
  • Platform: Linux

Issue:

I have a many to many relationship between AppRoles and AppUsers: each user HasMany roles and each role BelongsToMany users. Both the models use ulids: however, adding users after the line belongsToMany: AppUser causes the Blueprint to generate a migration where, instead of the usual foreignUlid, a foreignId is generated. If I remove the name it works flawlessly. I also have foreign key constraints active.

draft.yaml:

models:
  AppRole:
    ulid

    slug: string:20:unique
    name: string:50

    relationships:
      belongsToMany: AppUser:users
  
  AppUser:
    ulid
    
    username: string:255:unique
    password: password
    firstName: string:255
    lastName: string:255
    studies: string:255 nullable
    room: string:20 nullable
    telephone: string:20 nullable
    description: longtext
    
    softDeletes
    timestamps: false

    relationships:
      hasMany: AppRole:role
      belongsToMany: Group:group

  Group:
    name: string
    color: string

    relationships:
      hasMany: AppUser:user

Metadata

Metadata

Assignees

No one assigned

    Labels

    pendingThis issue is pending reviewquestionFurther information is requested

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions