You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
I'm trying to use the goose.Up function in my project, but I'm running into the error Could not update tables: Error 1054: Unknown column '$1' in 'field list'. I'm probably doing something wrong, but some help with this would be greatly appreciated.
Failing code
funcUpdateTables() error {
log.Println("Updating the tables.")
config, err:=config.New()
iferr!=nil {
log.Println("Could not access the config struct")
returnerr
}
conn, err:=connections.New()
iferr!=nil {
log.Println("Could not access the database")
returnerr
}
// conn is a sqlx.DB, so get the sql.DB pointer from that// config.MigrationsPath points to the db directory with the migrations file.iferr:=goose.Up(conn.DB, config.MigrationsPath); err!=nil {
log.Println("Could not update database")
returnerr
}
returnnil
}
funcCreateDefaults() error {
log.Println("Creating default entries.")
iferr:=CreateDefaultStatuses(); err!=nil {
returnerr
}
returnnil
}
Migrations file
-- +goose Up-- SQL in section 'Up' is executed when this migration is applied-- EnumsCREATETABLEStatusEnum(
id INT UNSIGNED NOT NULL AUTO_INCREMENT,
name VARCHAR(50) NOT NULL,
PRIMARY KEY(id),
UNIQUE(name)
);
CREATETABLEClassEnum(
id INT UNSIGNED NOT NULL AUTO_INCREMENT,
name VARCHAR(50) NOT NULL,
PRIMARY KEY(id),
UNIQUE(name)
);
CREATETABLEGenderEnum(
id INT UNSIGNED NOT NULL AUTO_INCREMENT,
name VARCHAR(50) NOT NULL,
other VARCHAR(150) NOT NULL,
PRIMARY KEY(id),
UNIQUE(name)
);
-- Roles and permissionsCREATETABLERole(
id INT UNSIGNED NOT NULL AUTO_INCREMENT,
status_id INT UNSIGNED NOT NULL,
name VARCHAR(100) NOT NULL,
isAdmin BOOLEANNOT NULL,
PRIMARY KEY(id),
UNIQUE(name),
CONSTRAINT statusRole_fkConstraint
FOREIGN KEY (status_id) REFERENCES StatusEnum (id)
);
CREATETABLEPermission(
id INT UNSIGNED NOT NULL AUTO_INCREMENT,
name VARCHAR(100) NOT NULL,
PRIMARY KEY(id),
UNIQUE(name)
);
CREATETABLERolePermission(
role_id INT UNSIGNED NOT NULL,
permission_id INT UNSIGNED NOT NULL,
CONSTRAINT roleRolePermission_fkConstraint
FOREIGN KEY (role_id) REFERENCES Role (id)
ON DELETE CASCADEONUPDATE CASCADE,
CONSTRAINT permissionRolePermission_fkConstraint
FOREIGN KEY (permission_id) REFERENCES Permission (id)
ON DELETE CASCADEONUPDATE CASCADE
);
-- Hero/Party classesCREATETABLEHero(
id INT UNSIGNED NOT NULL AUTO_INCREMENT,
firstName VARCHAR(50) NOT NULL,
lastName VARCHAR(50) NOT NULL,
email VARCHAR(200) NOT NULL,
gender_id INT UNSIGNED NOT NULL,
class_id INT UNSIGNED NOT NULL,
status_id INT UNSIGNED NOT NULL,
role_id INT UNSIGNED NOT NULL,
UNIQUE(email),
PRIMARY KEY(id),
CONSTRAINT statusHero_fkConstraint
FOREIGN KEY (status_id) REFERENCES StatusEnum (id),
CONSTRAINT genderHero_fkConstraint
FOREIGN KEY (gender_id) REFERENCES GenderEnum (id),
CONSTRAINT roleHero_fkConstraint
FOREIGN KEY (role_id) REFERENCES Role (id)
);
CREATETABLEParty(
id INT UNSIGNED NOT NULL AUTO_INCREMENT,
name VARCHAR(200) NOT NULL,
partyLeader_id INT UNSIGNED NOT NULL,
PRIMARY KEY(id),
CONSTRAINT heroParty_fkConstraint
FOREIGN KEY (id) REFERENCES Hero (id)
);
CREATETABLEHeroParty(
hero_id INT UNSIGNED NOT NULL,
party_id INT UNSIGNED NOT NULL,
CONSTRAINT heroHeroParty_fkConstraint
FOREIGN KEY (hero_id) REFERENCES Hero (id)
ON DELETE CASCADEONUPDATE CASCADE,
CONSTRAINT partyHeroParty_fkConstraint
FOREIGN KEY (party_id) REFERENCES Party (id)
ON DELETE CASCADEONUPDATE CASCADE
);
-- AuthenticationCREATETABLEAuth(
id INT UNSIGNED NOT NULL AUTO_INCREMENT,
seed CHAR(128) NOT NULL,
iterations INT UNSIGNED NOT NULL,
hashedPassword CHAR(128) NOT NULL,
hero_id INT UNSIGNED NOT NULL,
PRIMARY KEY(id),
CONSTRAINT heroAuth_fkConstraint
FOREIGN KEY (hero_id) REFERENCES Hero (id)
);
-- InvitationCREATETABLEInvitation(
id INT UNSIGNED NOT NULL AUTO_INCREMENT,
slug CHAR(128) NOT NULL,
status_id INT UNSIGNED NOT NULL,
party_id INT UNSIGNED NOT NULL,
PRIMARY KEY(id),
UNIQUE(slug),
CONSTRAINT statusInvitation_fkConstraint
FOREIGN KEY (status_id) REFERENCES StatusEnum (id),
CONSTRAINT partyInvitation_fkConstraint
FOREIGN KEY (party_id) REFERENCES Party (id)
ON DELETE CASCADEONUPDATE CASCADE
);
-- BlogCREATETABLEBlogPost(
id INT UNSIGNED NOT NULL AUTO_INCREMENT,
slug VARCHAR(200) NOT NULL,
title VARCHAR(200) NOT NULL,
body TEXTNOT NULL,
submitDate DATETIME NOT NULL DEFAULT CURRENT_TIMESTAMP,
displayDate DATETIME NOT NULL DEFAULT CURRENT_TIMESTAMP,
hero_id INT UNSIGNED NOT NULL,
PRIMARY KEY(id),
UNIQUE(slug),
CONSTRAINT heroBlogPost_fkConstraint
FOREIGN KEY (hero_id) REFERENCES Hero (id)
);
-- SurveyCREATETABLESurvey(
id INT UNSIGNED NOT NULL AUTO_INCREMENT,
description TEXTNOT NULL,
startDate DATETIME NOT NULL DEFAULT CURRENT_TIMESTAMP,
endDate DATETIME NOT NULL DEFAULT CURRENT_TIMESTAMP,
PRIMARY KEY(id)
);
CREATETABLEQuestion(
id INT UNSIGNED NOT NULL AUTO_INCREMENT,
survey_id INT UNSIGNED NOT NULL,
question JSON,
PRIMARY KEY(id),
CONSTRAINT surveyQuestion_fkConstraint
FOREIGN KEY (survey_id) REFERENCES Survey (id)
);
CREATETABLEResponse(
id INT UNSIGNED NOT NULL AUTO_INCREMENT,
question_id INT UNSIGNED NOT NULL,
hero_id INT UNSIGNED NOT NULL,
response JSON,
PRIMARY KEY(id),
CONSTRAINT questionResponse_fkConstraint
FOREIGN KEY (question_id) REFERENCES Question (id),
CONSTRAINT heroResponse_fkConstraint
FOREIGN KEY (hero_id) REFERENCES Hero (id)
);
-- +goose Down-- SQL section 'Down' is executed when this migration is rolled backDROPTABLE Response;
DROPTABLE Question;
DROPTABLE Survey;
DROPTABLE Invitation;
DROPTABLE BlogPost;
DROPTABLE Auth;
DROPTABLE HeroParty;
DROPTABLE Party;
DROPTABLE Hero;
DROPTABLE RolePermission;
DROPTABLE Permission;
DROPTABLE Role;
DROPTABLE StatusEnum;
DROPTABLE GenderEnum;
DROPTABLE ClassEnum;
The text was updated successfully, but these errors were encountered:
Hello,
I'm trying to use the
goose.Up
function in my project, but I'm running into the errorCould not update tables: Error 1054: Unknown column '$1' in 'field list'
. I'm probably doing something wrong, but some help with this would be greatly appreciated.Failing code
Migrations file
The text was updated successfully, but these errors were encountered: