cjmellor / level-up

Level-Up is a Laravel package introducing gamification into your applications. Users earn experience points (XP) and levels through interactions, while also unlocking achievements. It promotes engagement, competition, and fun through its dynamic leaderboard feature. Customisable to fit your specific needs

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

[Bug]: First Migration Bug

pablodiegoo opened this issue · comments

What happened?

Just trying to do first migration and had a issue with streak_history_table.

I changed the migration table as a placebo, but since i just did it, no idea if will face bugs because of that, so just sharing.

            $table->id();
            $table->foreignId(column: config(key: 'level-up.user.foreign_key'))->constrained(table: config(key: 'level-up.user.users_table'))->cascadeOnDelete();
            $table->foreignIdFor(model: Activity::class)->constrained(table: 'streak_activities');
            $table->integer(column: 'count')->default(value: 1);
            $table->timestamp(column: 'started_at')**->nullable(**);
            $table->timestamp(column: 'ended_at'**)->nullable()**;
            $table->timestamps();

`PS C:\Users\tatia\Dropbox\Coding\Laravel\l96lab> php artisan migrate

INFO Running migrations.

2023_10_31_000158_create_streak_histories_table ...................................................... 11ms FAIL

Illuminate\Database\QueryException

SQLSTATE[42000]: Syntax error or access violation: 1067 Invalid default value for 'ended_at' (Connection: mysql, SQL: create table streak_histories (id bigint unsigned not null auto_increment primary key, user_id bigint unsigned not null, activity_id bigint unsigned not null, count int not null default '1', started_at timestamp not null, ended_at timestamp not null, created_at timestamp null, updated_at timestamp null) default character set utf8mb4 collate 'utf8mb4_unicode_ci')

at vendor\laravel\framework\src\Illuminate\Database\Connection.php:801
797▕ $this->getName(), $query, $this->prepareBindings($bindings), $e
798▕ );
799▕ }
800▕
➜ 801▕ throw new QueryException(
802▕ $this->getName(), $query, $this->prepareBindings($bindings), $e
803▕ );
804▕ }
805▕ }

1 vendor\laravel\framework\src\Illuminate\Database\Connection.php:580
PDOException::("SQLSTATE[42000]: Syntax error or access violation: 1067 Invalid default value for 'ended_at'")

2 vendor\laravel\framework\src\Illuminate\Database\Connection.php:580
PDOStatement::execute()
`

How to reproduce the bug

Only did a migration on my actual project and had this error.

Package Version

1.1

PHP Version

8.2

Laravel Version

10

Which operating systems does with happen with?

No response

Notes

I made a pull request if that solution make sense. Ignore if dont.