Skip to content

MySQL Schema Issue inside User table and Enrollment table #202

@csandrew-dev

Description

@csandrew-dev

Environment

  • M1 Pro MacBook Pro
  • nanomdm v0.8.0
$ mysql --version
mysql  Ver 9.4.0 for macos15.4 on arm64 (Homebrew)

Error

When trying to import the mysql schema into my mysql db. I receive the following error:

$ mysql -u root nanomdm < schema.sql
ERROR 6125 (HY000) at line 79: Failed to add the foreign key constraint. Missing unique key for constraint 'enrollments_ibfk_2' in the referenced table 'users'

Possible fix

In the mysql schema.sql file, on line 64 add UNIQUE(id),

created_at TIMESTAMP DEFAULT CURRENT_TIMESTAMP,
updated_at TIMESTAMP DEFAULT CURRENT_TIMESTAMP ON UPDATE CURRENT_TIMESTAMP,
PRIMARY KEY (id, device_id),
FOREIGN KEY (device_id)
REFERENCES devices (id)
ON DELETE CASCADE ON UPDATE CASCADE,

After changing that line and removing the artifacts left in the DB after a partially ran sql script, it seems to build the DB fine and work.

Let me know what you think!

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions