Laravel Model get's wrong ID after saving - laravel

I've got a Laravel application (5.1.28) which I have running on a development server and production server.
dev:
php 5.6.13
mysql 5.6.19
prod:
php 5.6.16
mysql 5.5.27
mysql table:
CREATE TABLE testquestions (
id bigint(20) UNSIGNED NOT NULL,
testquestiongroup_id bigint(20) NOT NULL,
description varchar(255) COLLATE utf8_unicode_ci DEFAULT NULL,
type varchar(255) COLLATE utf8_unicode_ci NOT NULL,
created_at timestamp NOT NULL DEFAULT '0000-00-00 00:00:00',
updated_at timestamp NOT NULL DEFAULT '0000-00-00 00:00:00'
) ENGINE=InnoDB DEFAULT CHARSET=utf8 COLLATE=utf8_unicode_ci;
And the following php code;
$question = new Question();
$question->testquestiongroup_id = $questiongroup->id;
$question->save();
The code on my dev and prod environment are the same. Als the database content are the same, copied from prod to dev.
When I run this code my $question object will get a wrong ID back from mysql(?). When I check MySQL there is a new record with a (good) ID, but this ID isn't returned to my object. It get the same wrong ID over and over again. The wrong ID is from an object added 4 months ago.
This problem doesn't occur on my dev environment.
Is there some bug in MySQL or am I doing something wrong? Thanks
UPDATE 12febr
The problem get keeping weirder!
I tried the following code after inserting my code ($question->save())
var_dump($question);
var_dump(\DB::getPdo()->lastInsertId());
My question object gives a different ID ($question->id) than \DB::getPdo()->lastInsertId(). The returned ID from the $question object stays the wrong ID. The lastInsertId function returns the right ID!
Does it matter that the field is a BIGINT(20) ?

I have some similar problem and finally solved it. Not the same, but it is also about laravel-model-gets-wrong-id-after-saving, so I hope I can post it here to let someone having my problem solve it.
My solution: Check about the DB::getPdo()->lastInsertId(). If it is also wrong, then check whether you have some sql insert statement inside DB::listen callback.
I am a fool for I tried to log my sql statement inside DB::listen by using an insert statement. This is the problem.

I had some problems with id's in laravel/eloquent.
Setting the incrementing variable to false in the specific model helped me most of the time.
Perhaps this will help you too.

Related

Two sites using different userdata but the same session domain in Codeigniter

I'm using Codeigniter. I have 2 sites, they look like that:
http://example.com/system/
http://example.com/system2/
These two systems have different userdata. In first site, I haven't set a parameter class, but in the second I've set it. When user first open http://example.com/system/ and then open
http://example.com/system2/ it's showing error message: undefined index class. Both sites in session domain is: example.com.
How to make to have different session? Maybe I have to set different domain in session? I haven't set it before, how to do that?
On each system use database and change the database name as well as the cookie name in config.php
$config['sess_table_name'] = 'system_x_session';
$config['sess_cookie_name'] = 'system_x_cookie';
where x is your system number or you can name it any name
don't forget to create the two tables in your database
CREATE TABLE IF NOT EXISTS `system_x_session` (
session_id varchar(40) DEFAULT '0' NOT NULL,
ip_address varchar(45) DEFAULT '0' NOT NULL,
user_agent varchar(120) NOT NULL,
last_activity int(10) unsigned DEFAULT 0 NOT NULL,
user_data text NOT NULL,
PRIMARY KEY (session_id),
KEY `last_activity_idx` (`last_activity`)
);
this will make your sessions independent from each other and you can check their content with phpmyadmin and the likes
hope that helps

Update Not Null Column with Default Value Fails

Please forgive me if this is a basic question. I'm not much of an Oracle developer and Google has failed me so I turn to you.
I have two schema's in the same database. They both have the same structure. I have a table with a column defined as...
longitude_coordinate NUMBER(16,8) default 0 not null,
...if I run the query...
UPDATE table SET longitude_coordinate = null WHERE id = xxxxxxxx
...on one schema it succeeds on the other it fails with the error....
ORA-01407:
cannot update ("SCHEMA"."TABLE"."LONGITUDE_COORDINATE") to NULL.
I'm assuming there must be some global option but I can't locate it for the life of me.
Looks like you are trying to update not null column with null values and it will throw error for obvious reasons.
Can you check whether that not null constraint was disabled in the schema where the query was executed successfully.
you are trying to set null values to a column that does not support nulls values,
This should work:
UPDATE table SET longitude_coordinate = 0 WHERE id = xxxxxxxx
hope this helps !

joomla broken and can't figure it out

Transfering a Joomla site to a new server, not really experienced.
Apache is set up, MySQL is live and the DB was imported, the user/pass/path and config were updated accordingly.
The DB connected and gave me this wierd error. I did some research and someone suggested to drop the jos_ table and recreate it by doing the following:
CREATE TABLE IF NOT EXISTS `jos_session` (
`username` varchar(150) default '',
`time` varchar(14) default '',
`session_id` varchar(200) NOT NULL default '0',
`guest` tinyint(4) default '1',
`userid` int(11) default '0',
`usertype` varchar(50) default '',
`gid` tinyint(3) unsigned NOT NULL default '0',
`client_id` tinyint(3) unsigned NOT NULL default '0',
`data` longtext,
PRIMARY KEY (`session_id`(64)),
KEY `whosonline` (`guest`,`usertype`),
KEY `userid` (`userid`),
KEY `time` (`time`)
) ENGINE=MyISAM DEFAULT CHARSET=utf8;
So, now that that was done, I get the following:
404 - Component not found
You may not be able to visit this page because of:
an out-of-date bookmark/favourite
a search engine that has an out-of-date listing for this site
a mistyped address
you have no access to this page
The requested resource was not found.
An error has occurred while processing your request.
Please try one of the following pages:
Home Page
When I try to access the homepage (index.php) it does the same thing....
What the heck did I do and how do I fix this?
Any help is most appreciated -
ORIGINAL ERROR (Just restored again):
jtablesession::Store Failed
DB function failed with error number 1146
Table 'plumblev_joom347.jos_session' doesn't exist SQL=INSERT INTO jos_session ( session_id,time,username,gid,guest,client_id ) VALUES ( '9890e7d1fa915e26d17121dd4eed8004','1369667714','','0','1','0' )
You should avoid to move a Joomla! site manually, if you're not familiar with that. There are a lot of settings, which have to be adjusted.
Better use Akeeba Backup together with Kickstart for that. It even allows you to change the database prefix during transfer.
Moving shouldn't be a problem as long as you adjust the configuration.php file accordingly, especially the paths.
I would just try and move the tables from the old server again to the new one, overwriting the new tables. That is as long as you use the same Joomla version on both servers.
Can you access the administrator? If so, make sure you have a default page set and also that it is set to public.

PyroCMS Using 2.0 Issue with registering new users persists after upgrade

I get the following error when registering a new user ( not from the admin end)
as a fix , I tried updating to 2.1 but that didnt solve it.. it is worth noting that the registration form shows only 3 fields :
Email, Password and First name ..
I realize it has to do with a setting somewhere but would love any advice to help me save some time.
Thanks
Either run this query:
ALTER TABLE `default_profiles` CHANGE `last_name` `last_name` VARCHAR( 50 ) CHARACTER SET utf8 COLLATE utf8_unicode_ci NOT NULL DEFAULT ''
Or on the control panel go to settings->users and try changing "require last names"
Did you change the available profile fields?
Are you running a clean install of 2.1 or did you upgrade?
Just set the default value for the lastname field in the 'Default_profiles' table. Then it will work fine.

IONIZE CMS post installation problem

I decided to try Ionize cms which is build over CodeIgnitor. I have my apache, php , mysql installed seperately. When I finished installing the cms successfully, I cannot access the website. Some weird errors occurs like
Call to a member function num_rows() on a non-object in ... \ionize-0.9\application\models\article_model.php on line 224
I got frustated and searched many places. Later I tested the CMS in WAMP, and there it worked.
Now I have no idea, what is going on, everything the CMS needs to run, is tested during the installation. I dont have any idea.... how to solve it. Please help me
For one unknown reason, all the tables of the database weren't installed. Ionize currently doesn't check that situation. If it works on one server (Wamp) and not on one other (manually LAMP installed server), compare the tables list on each system.
I had this same issue on a WAMP server and the reason was that it couldn't created the article_type table.
I'd suggest checking your database to see if that table exist.
If it doesn't take a look at the data.sql file and try to run only that create table section. It should spit out an error. In my case the description text NOT NULL default "" was throwing an error (BLOB/TEXT column 'description can't have a default value).
I fixed it by making sure description doesn't have a default value.
CREATE TABLE IF NOT EXISTS article_type (
id_type int(11) unsigned NOT NULL auto_increment,
type varchar(50) collate utf8_unicode_ci NOT NULL,
ordering int(11) default 0,
description text NOT NULL,
type_flag TINYINT( 1 ) NOT NULL default 0,
PRIMARY KEY (id_type)
) ENGINE=InnoDB DEFAULT CHARSET=utf8 COLLATE=utf8_unicode_ci AUTO_INCREMENT=1 COMMENT='0.9.7';

Resources