Hi I am new to creating factories on Laravel and I am setting up a blog website. I had this going just fine and now it isn't working anymore.
When I use "tinker" to add fake data using (App/Models/Post::factory(30)->create();), below error keep occurs. Could anyone please educate me why this error occurs?
App/Models/Post::factory(30)->create();
PHP Warning: Use of undefined constant App - assumed 'App' (this will throw an Error in a future version of PHP) in F:\coding\laravel\test-laraveleval()'d code on line 1
PHP Warning: Use of undefined constant Models - assumed 'Models' (this will throw an Error in a future version of PHP) in F:\coding\laravel\test-laraveleval()'d code on line 1
PHP Warning: A non-numeric value encountered in F:\coding\laravel\test-laraveleval()'d code on line 1
PHP Warning: A non-numeric value encountered in F:\coding\laravel\test-laraveleval()'d code on line 1
PHP Warning: Division by zero in F:\coding\laravel\test-laraveleval()'d code on line 1
[!] Aliasing 'Post' to 'App\Models\Post' for this Tinker session.
Illuminate\Database\QueryException with message 'SQLSTATE[23000]: Integrity constraint violation: 1062 Duplicate entry 'sint' for key 'categories_name_unique' (SQL: insert into categories (name, slug, updated_at, created_at) values (sint, ut-quisquam-et-et-tenetur-molestias-in-dolor-voluptatum, 2022-03-16 07:11:05, 2022-03-16 07:11:05))
'
You have to define factory rules such that you have a constraint in your database that checks for category name uniqueness.
You should read how to write a custom factory in Laravel 8:Examples how to generate factories.
Related
I'm tryin to import and excel file to my SQL Server Database but when I try to create the form to upload the file I get this error:
Illuminate\Database\QueryException
SQLSTATE[42000]: [Microsoft][ODBC Driver 17 for SQL Server][SQL Server]Error converting data type nvarchar to bigint. (SQL: select top 1 * from [schedules] where [schedules].[id] = import)
Screenshoot of error
Even when I have the function in the controller it throws this error. Seems that is trying to get 1 record from database but cannot pass the nvarchar to match the ID column.
I have checked the documentation and nothing. Made it a few times, different methods with same error.
Seems that I figured it out. It was problem with the routing calling de show function
I had the same issue and trying to find the solution came upon this question. Thankfully I read the comments as Fernando's solution was also mine.
This was caused by a misordered Route in web.php
Route::Get('label/{label}' ...
...
Route::Get('label/create' ...
I swapped the order and all fixed
Route::Get('label/create' ...
...
Route::Get('label/{label}' ...
This question already has answers here:
Base table or view not found error
(2 answers)
Closed 3 years ago.
Before copying this project everything was ok but after copying this project to another laptop I am not able to migrate the database error
Illuminate\Database\QueryException : SQLSTATE[42S02]: Base table or view not found: 1146 Table 'discussionforum.channels' doesn't exist (SQL: select * from `channels`)
at /opt/lampp/htdocs/discussionforum/vendor/laravel/framework/src/Illuminate/Database/Connection.php:665
661| // If an exception occurs when attempting to run a query, we'll format the error
662| // message to include the bindings with SQL, which will make this exception a
663| // lot more helpful to the developer instead of just the database's errors.
664| catch (Exception $e) {
> 665| throw new QueryException(
666| $query, $this->prepareBindings($bindings), $e
667| );
668| }
669|
Exception trace:
1 Illuminate\Foundation\Application::Illuminate\Foundation\{closure}(Object(App\Providers\AppServiceProvider))
[internal]:0
2 PDOException::("SQLSTATE[42S02]: Base table or view not found: 1146 Table 'discussionforum.channels' doesn't exist")
/opt/lampp/htdocs/discussionforum/vendor/laravel/framework/src/Illuminate/Database/Connection.php:327
Please use the argument -v to see more details.
You should check AppServiceProvider or other providers which boot before migrate, if you use some table or model in providers u not able to use migration when that table doesn't exist.
If you look better there is error in
1 Illuminate\Foundation\Application::Illuminate\Foundation\{closure}(Object(App\Providers\AppServiceProvider))
[internal]:0
Check providers which using models before any table exists.
If u insist to use model in provider, you should check is it exists before of usage, like this:
Schema::hasTable('mytable'); // off course schema must be imported.
If u post content of you're providers, it will help.
If you don't need to preserve the current data
you could try resetting your data using
php artisan migrate:refresh --seed
and/or delete and recreate your
"database.(sql extension)" file
In my migration I have two extra timestamp
$table->timestamp('starts_at');
$table->timestamp('ends_at');
I dont want them to be nullable,problem is,when i run php artisan migrate
I returns
Syntax error or access violation: 1067 Invalid default value for 'ends_at'
I have $table->timestamps() at the bottom.
How can I have my custom timestamp column/s and not nullable
A way around is to simply put nullable() at the end but its not a fix.using laravel 5.7
I hope you are looking for datetime data type for that field.
Try the below code.
$table->datetime('starts_at');
$table->datetime('ends_at');
if you want to make this field as nullable try below.
$table->dateTime('starts_at')->nullable();
$table->dateTime('ends_at')->nullable();
You should try this:
$table->timestamp('starts_at');
$table->timestamp('ends_at')->default('0000-00-00 00:00:00');
I am working on a project with codeigniter and all of a sudden I started getting this kind of error message.
And it is coming from the system folder, database driver, language.
Here is the error message
A Database Error occurred
Error Number 1364
Field 'english' doesn't have a default value
INSERT INTO 'language' ('Phrase') VALUES ('Question')
Filename C:\Wamp64\www\sms\system\database\DB_driver.php
Line Number : 330
Your language table has English column, there is you have not set the default value and you are trying to insert in language table without English column value.
That's it.
Thanks
We try to create a replication with a view using SLT (SAP Landscape Transformation) Replication Server.
Views need to be defined in LTRS !?
When I try to make such a definition I get the error:
SQL0104N An unexpected token ")" was found
following "K" ADD PRIMARY KEY (", Expected tokens
may include "<unique_col_list>". SQLSTATE=42601
This error occurs if there is no primary key in the source table.
Hence the SQL generated by SAP results in an error. Obviously they did not check first if the conditions are met. As a result the error message does only gives an indirect hint.