nova-framework / framework

Demo application using Nova - this is an extensive playground, use "app" repository for real applications.
http://novaframework.com/
MIT License
418 stars 210 forks source link

create table query throwing error "Invalid default value" #2064

Closed yogimishra96 closed 6 years ago

yogimishra96 commented 6 years ago

faced this issue

screenshot from 2018-04-11 17-17-09

than what I did

changed $table->timestamp('created_at')->default('0000-00-00 00:00:00'); $table->timestamp('updated_at')->default('0000-00-00 00:00:00');

to

$table->timestamp('created_at'); $table->timestamp('updated_at');

/var/www/html/nova/app/Modules/Platform/Database/Migrations/2017_10_07_105238_create_user_tokens_table.php

CREATE TABLE nova_user_tokens( id INT UNSIGNED NOT NULL AUTO_INCREMENT PRIMARY KEY, email VARCHAR(255) NOT NULL, token VARCHAR(100) NOT NULL, created_at TIMESTAMP DEFAULT CURRENT_TIMESTAMP NOT NULL, updated_at TIMESTAMP DEFAULT CURRENT_TIMESTAMP NOT NULL ) DEFAULT CHARACTER SET utf8 COLLATE utf8_general_ci

LuckyCyborg commented 6 years ago

If you try to learn Nova right now, I strongly suggest you to use the latest Nova 4: https://github.com/nova-framework/framework/releases/tag/4.0.51

You can use a command like:

composer create-project nova-framework/framework foldername 4.* -s dev

Anyway the current Nova 4 does not differ so much of latest Nova 3 releases, excluding the re-organizing Modules and Themes support and adding some new features, one most important being the Packages support.

BUT, this repository contains an example app, only for your learning and study. Do not use this code for production!

IF you indent to develop your own production site, I strongly recommend to use instead this repository:

composer create-project nova-framework/app foldername 4.* -s dev

And for initializing the database, to use these commands, in that specific order:

php forge migrate:install
php forge migrate
php forge db:seed
php forge package:migrate
php forge package:seed

You will need to use package commands to migrate the Modules, because in Nova 4 both the Modules and Themes are basically special types of Packages.

Also, to note that manually creating of database tables may conflict with the Database Migration and Seeding, then I strongly recommend you to learn to write your own migrations and seeders instead.

PS. Your adjusting of the timestamps in migrations is perfect valid for customizing for your particular database, but I for one, for giving them a default value, I would use instead:

$table->timestamp('created_at')->nullable();
$table->timestamp('updated_at')->nullable();

OR, even better:

$table->nullableTimestamps();
yogimishra96 commented 6 years ago

Thanks LuckyCyborg !

On Wed, Apr 11, 2018 at 5:32 PM, LuckyCyborg notifications@github.com wrote:

If you try to learn Nova, I strongly suggest you to use the latest Nova 4: https://github.com/nova-framework/framework/releases/tag/4.0.51 , anyway the Nova 4 does not differ so much of latest Nova 3 releases, excluding re-organizing the Modules and Themes support and adding some new features, one most important being the Packages support.

And for initializing the database, to use these commands, in order

php forge migrate:installphp forge migratephp forge db:seedphp forge package:migratephp forge package:seed

You will need to use package commands, because in Nova 4 both the Modules and Themes are special cases of Packages.

Also, to note that manually creating of database table may conflict with the Database Migration and Seeding, then I strongly recommend you to learn to write your own migrations and seeders instead.

— You are receiving this because you authored the thread. Reply to this email directly, view it on GitHub https://github.com/nova-framework/framework/issues/2064#issuecomment-380427315, or mute the thread https://github.com/notifications/unsubscribe-auth/ALrkJEZtXZdCHqu3EIXnxsPhKthq2Lduks5tnfDJgaJpZM4TP4VY .