Insert query using dbForge is not inserting default values - php

I am trying to insert default values into a newly created table, however the table is created with no values. How can I insert values using dbForge after creating the table?
My Controller code is as follows:
$fields = array('id' =>
array('type' => 'INT','constraint' => 11,
'unsigned' => TRUE,'auto_increment' => TRUE),
'home_bg' => array('type' => 'VARCHAR','constraint' => '200',),
'login_bg' => array('type' => 'VARCHAR','constraint' => '200',),
'other_bg' => array('type' =>'VARCHAR','constraint' => '200',),
'uploaded_on' => array('type' => 'DATE',),);
$this->dbforge->add_field($fields);
$this->dbforge->add_key('id', TRUE);
$this->dbforge->create_table('pr_backgrounds', TRUE);

Try out this
$fields = array(
'id' => array(
'type' => 'INT',
'constraint' => 11,
'unsigned' => TRUE,
'auto_increment' => TRUE
),
'home_bg' => array(
'type' => 'VARCHAR',
'constraint' => '200',
),
'other_bg' => array(
'type' =>'VARCHAR',
'constraint' => '200',
),
'uploaded_on' => array(
'type' => 'DATE'
),
);
$this->dbforge->add_field($fields);
$this->dbforge->add_key('id', TRUE);
$this->dbforge->create_table('ipn_log', TRUE);

Related

connect to another db and update a row in codeigniter

I am trying to update the already existing username field where id=1 , from admin#something.com to the string in $username but the default database is being updated , i want to connect to the newly created db and update the username field where id=1 in pr_users table but unable to connect to the newly created db and update the field.
I am calling a model to update the table i.e using $data['applicant_rows'] = $this->mod_common->add_new_user($email,$userid,$username); somehow the statements after foreach($sqls as $statement) is not working, Please help
below is my controller code:
Controller: login.php
public function save_userinput()
{
//code goes here
// for example: getting the post values of the form:
$form_data = $this->input->post();
// or just the username:
$username = $this->input->post("username");
$email = $this->input->post("email");
$userid = 1;
$data['applicant_rows'] = $this->mod_common->update_table_with_user_for_the_first_time($email,$userid,$username);
//$data['workspace'] = $this->mod_common->update_admin($email);
// $this->admin_list->manage_package();
$this->load->dbforge();
if ($this->dbforge->create_database($username))
{
try{
$current_database = $username;
$this->db->database = $current_database;
$data['applicant_rows'] = $this->mod_common->add_new_user($email,$userid,$username);
$this->db->close();
$config['hostname'] = "localhost";
$config['username'] = "root";
$config['password'] = "";
$config['database'] = $current_database;
$config['dbdriver'] = "mysql";
$config['dbprefix'] = $username;
$config['pconnect'] = FALSE;
$config['db_debug'] = TRUE;
$config['cache_on'] = FALSE;
$config['cachedir'] = "";
$config['char_set'] = "utf8";
$config['dbcollat'] = "utf8_general_ci";
$this->load->database($config);
$fields = array(
'id' => array(
'type' => 'INT',
'constraint' => 11,
'unsigned' => TRUE,
'auto_increment' => TRUE
),
'home_bg' => array(
'type' => 'VARCHAR',
'constraint' => '200',
),
'login_bg' => array(
'type' => 'VARCHAR',
'constraint' => '200',
),
'other_bg' => array(
'type' =>'VARCHAR',
'constraint' => '200',
),
'uploaded_on' => array(
'type' => 'DATE',
),
);
$this->dbforge->add_field($fields);
$this->dbforge->add_key('id', TRUE);
$this->dbforge->create_table('pr_backgrounds', TRUE);
$fields = array(
'id' => array(
'type' => 'BIGINT',
'constraint' => 15,
'unsigned' => TRUE,
'auto_increment' => TRUE
),
'username' => array(
'type' => 'VARCHAR',
'constraint' => '255',
'default' => 'admin#ju.com',
),
'userpass' => array(
'type' => 'VARCHAR',
'constraint' => '255',
'default' => '65e1b655a6d6f4cbed20554d3b52521a743afdc0',
),
'email' => array(
'type' =>'VARCHAR',
'constraint' => '255',
'default' => 'admin#team.com',
),
'departmentid' => array(
'type' => 'BIGINT',
'constraint' => 15,
'default' => '1',
),
'userroleid' => array(
'type' => 'BIGINT',
'constraint' => 15,
'default' => '4',
),
'managerid' => array(
'type' =>'VARCHAR',
'constraint' => '255',
'default' => '10',
),
'userlevel' => array(
'type' => 'INT',
'constraint' => 11,
),
'branchid' => array(
'type' => 'INT',
'constraint' => 11,
'default' => '2',
),
'is_global' => array(
'type' => 'TINYINT',
'constraint' => 4,
'default' => '0',
),
'registrationtime' => array(
'type' => 'INT',
'constraint' => 10,
),
'timemodified' => array(
'type' => 'BIGINT',
'constraint' => 10,
),
'modifierid' => array(
'type' => 'BIGINT',
'constraint' => 15,
),
'status' => array(
'type' => 'TINYINT',
'constraint' => 1,
),
'deleted' => array(
'type' => 'TINYINT',
'constraint' => 1,
),
'temppass' => array(
'type' => 'VARCHAR',
'constraint' => 20,
),
'temppassvalidtill' => array(
'type' => 'BIGINT',
'constraint' => 15,
),
'lastlogin' => array(
'type' => 'BIGINT',
'constraint' => 10,
),
'lastrefresh' => array(
'type' => 'BIGINT',
'constraint' => 15,
),
'lastloginip' => array(
'type' => 'VARCHAR',
'constraint' => 20,
),
'if_online' => array(
'type' => 'INT',
'constraint' => 11,
),
'pfield' => array(
'type' => 'VARCHAR',
'constraint' => 255,
),
);
$this->dbforge->add_field($fields);
$this->dbforge->add_key('id', TRUE);
$this->dbforge->create_table('pr_users', TRUE);
$sql = file_get_contents("assets/zipbizzlatestdb.sql");
/*
Assuming you have an SQL file (or string) you want to run as part of the migration, which has a number of statements...
CI migration only allows you to run one statement at a time. If the SQL is generated, it's annoying to split it up and create separate statements.
This small script splits the statements allowing you to run them all in one go.*/
$sqls = explode(';', $sql);
array_pop($sqls);
foreach($sqls as $statement){
$statment = $statement . ";";
$this->db->query($statement);
}
$this->loadanothercontroller();
}
catch(Exception $e){
echo "This name already exists in our database , Please choose another company name";
die;
}
}
// then do whatever you want with it :)
}
Model: mod_common.php
function add_new_user($email,$password,$username)
{
/* $sqls="INSERT INTO pr_users (username,userpass,email,departmentid,userroleid,managerid,userlevel,branchid,is_global,registrationtime,timemodified,modifierid,status,deleted,temppass,temppassvalidtill,lastlogin,lastrefresh,lastloginip,if_online,pfield) values ('$email','65e1b655a6d6f4cbed20554d3b52521a743afdc0','$email','1','4','10','4','2','0','0','1491557947','1','1','0','','0','1492084067','1492084083','1','0','unfold983$')";
$query=$this->db->query($sqls);*/
$defaultDB = $this->load->database('default', TRUE);
$id=1;
$col_name = 'username';
$sql="UPDATE pr_users
SET `".$col_name."` = '".addslashes($email)."'
WHERE `id` = '".$id."'";
$query=$this->db->query($sql);
if ($this->db->affected_rows() > 0) {
echo "Success";
# return TRUE;
}
else {
echo "failed";
# return FALSE;
}
}
pr_users table

Not able to call another controller method in codeigniter

I am creating a new database as part of the setup for each of my tenants, db is created successfully but is taking a lot of time , approx 5 min, on the other hand i am not able to call another controller method i.e admin_list controller and manage_package method inside it. This is my controller code:
<?php
class login extends CI_Controller
{
var $data;
function __construct() {
parent::__construct();
$this->load->helper('cookie');
require_once(APPPATH.'controllers/admin_list.php');
$is_admin_logged_in = $this->admin_init_elements->admin_logged_in_status();
global $USER;
if($is_admin_logged_in == TRUE){
redirect('home');
//;
}
//populate viewfor header / footer elements
$this->admin_init_elements->init_elements('N');
$this->load->model('mod_login');
}
public function save_userinput()
{
//code goes here
// for example: getting the post values of the form:
$form_data = $this->input->post();
// or just the username:
$username = $this->input->post("username");
echo $username;
// $this->admin_list->manage_package();
$this->load->dbforge();
if ($this->dbforge->create_database($username))
{
try{
$current_database = $username;
$this->db->database = $current_database;
$this->db->close();
$config['hostname'] = "localhost";
$config['username'] = "root";
$config['password'] = "";
$config['database'] = $current_database;
$config['dbdriver'] = "mysql";
$config['dbprefix'] = $username;
$config['pconnect'] = FALSE;
$config['db_debug'] = TRUE;
$config['cache_on'] = FALSE;
$config['cachedir'] = "";
$config['char_set'] = "utf8";
$config['dbcollat'] = "utf8_general_ci";
$this->load->database($config);
$fields = array(
'id' => array(
'type' => 'INT',
'constraint' => 11,
'unsigned' => TRUE,
'auto_increment' => TRUE
),
'home_bg' => array(
'type' => 'VARCHAR',
'constraint' => '200',
),
'login_bg' => array(
'type' => 'VARCHAR',
'constraint' => '200',
),
'other_bg' => array(
'type' =>'VARCHAR',
'constraint' => '200',
),
'uploaded_on' => array(
'type' => 'DATE',
),
);
$this->dbforge->add_field($fields);
$this->dbforge->add_key('id', TRUE);
$this->dbforge->create_table('pr_backgrounds', TRUE);
$fields = array(
'id' => array(
'type' => 'BIGINT',
'constraint' => 15,
'unsigned' => TRUE,
'auto_increment' => TRUE
),
'username' => array(
'type' => 'VARCHAR',
'constraint' => '255',
'default' => 'admin#fold.com',
),
'userpass' => array(
'type' => 'VARCHAR',
'constraint' => '255',
'default' => '65e1b655a6d6f4cbed20554d3b52521a743afdc0',
),
'email' => array(
'type' =>'VARCHAR',
'constraint' => '255',
'default' => 'admin#fold.com',
),
'departmentid' => array(
'type' => 'BIGINT',
'constraint' => 15,
'default' => '1',
),
'userroleid' => array(
'type' => 'BIGINT',
'constraint' => 15,
'default' => '4',
),
'managerid' => array(
'type' =>'VARCHAR',
'constraint' => '255',
'default' => '10',
),
'userlevel' => array(
'type' => 'INT',
'constraint' => 11,
),
'branchid' => array(
'type' => 'INT',
'constraint' => 11,
'default' => '2',
),
'is_global' => array(
'type' => 'TINYINT',
'constraint' => 4,
'default' => '0',
),
'registrationtime' => array(
'type' => 'INT',
'constraint' => 10,
),
'timemodified' => array(
'type' => 'BIGINT',
'constraint' => 10,
),
'modifierid' => array(
'type' => 'BIGINT',
'constraint' => 15,
),
'status' => array(
'type' => 'TINYINT',
'constraint' => 1,
),
'deleted' => array(
'type' => 'TINYINT',
'constraint' => 1,
),
'temppass' => array(
'type' => 'VARCHAR',
'constraint' => 20,
),
'temppassvalidtill' => array(
'type' => 'BIGINT',
'constraint' => 15,
),
'lastlogin' => array(
'type' => 'BIGINT',
'constraint' => 10,
),
'lastrefresh' => array(
'type' => 'BIGINT',
'constraint' => 15,
),
'lastloginip' => array(
'type' => 'VARCHAR',
'constraint' => 20,
),
'if_online' => array(
'type' => 'INT',
'constraint' => 11,
),
'pfield' => array(
'type' => 'VARCHAR',
'constraint' => 255,
),
);
$this->dbforge->add_field($fields);
$this->dbforge->add_key('id', TRUE);
$this->dbforge->create_table('pr_users', TRUE);
$sql = file_get_contents("assets/bizzlatestdb.sql");
/*
Assuming you have an SQL file (or string) you want to run as part of the migration, which has a number of statements...
CI migration only allows you to run one statement at a time. If the SQL is generated, it's annoying to split it up and create separate statements.
This small script splits the statements allowing you to run them all in one go.
*/
$sqls = explode(';', $sql);
array_pop($sqls);
foreach($sqls as $statement){
$statment = $statement . ";";
$this->db->query($statement);
}
}
catch(Exception $e){
echo "This name already exists in our database , Please choose another company name";
die;
}
$this->admin_list->manage_package();
}
// then do whatever you want with it :)
}
function index(){
$this->load->view('login', $this->data);
}
}
?>
You can load controller as library in Codeigniter2. But I don't think it is possible in Codeigniter3.
Load Controller as Library :
$this->load->library('../controllers/controller_name');
# Calling Methdod
$this->controller_name->method_name();

How to set Datetime as type for a column on Codeigniter migration

I am doing a migration file, and there is a field on a table wich type should be DateTime, and the default value CURRENT_TIMESTAMP. What I have until now is the next:
'date' => array(
'type' => 'DATETIME',
),
I think it is right... but I still need set the default value... definitely, what I want to do is make the translation from sql to codeigniter migration of this:
`date` datetime NOT NULL DEFAULT CURRENT_TIMESTAMP
Thanks in advance.
Best way to Codeigniter migration:
$this->dbforge->add_field(array(
'id' => array(
'type' => 'INT',
'constraint' => 5,
'unsigned' => TRUE,
'auto_increment' => TRUE
),
'first_name' => array(
'type' => 'VARCHAR',
'constraint' => '50',
'null'=>false,
),
'last_name' => array(
'type' => 'VARCHAR',
'constraint' => 50,
'null'=>false,
),
'email' => array(
'type' => 'VARCHAR',
'constraint' => 100,
'unique' => true,
'null'=>false,
),
'mobile' => array(
'type' => 'BIGINT',
'constraint' => 15,
'null'=>true,
),
'password' => array(
'type' => 'VARCHAR',
'constraint' => 255,
'null'=>false,
),
'image' => array(
'type' => 'VARCHAR',
'constraint' => 255,
'null'=>true,
),
'status' => array(
'type' => 'TINYINT',
'constraint' => 3,
'default'=>1,
),
'delete_status' => array(
'type' => 'TINYINT',
'constraint' => 3,
'default'=>1,
),
'created_date datetime default current_timestamp',
'updated_date datetime default current_timestamp on update current_timestamp',
));
You can try like this.Need to use timestamp.See an example below..
'created_at' => array('type' => 'timestamp')
I have found this answer in the codeigniter forum. Basically, it says that I can use created_at timestamp default current_timestampinstead of key->value array. And there are other interesant things like 'on update':
'updated_at' => array(
'type' => 'varchar',
'constraint' => 250,
'null' => true,
'on update' => 'NOW()'
)
I hope it can to help anyone on future.

how to set on update attributes in a timestamp field using dbforge class in codeigniter 3

I want to set on update attributes for getting an updated time for my application. Here is my Model Code:
public function createDatabase() {
$testdatabase = "testdatabase";
$this->dbforge->create_database($testdatabase);
$this->db->db_select($testdatabase);
$fields = array(
'id' => array(
'type' => 'INT',
'constraint' => 1,
'unsigned' => TRUE,
),
'name' => array(
'type' => 'VARCHAR',
'constraint' => '100',
),
'establishment_date' => array(
'type' => 'VARCHAR',
'constraint' => '50',
'null' => TRUE,
),
'package' => array(
'type' => 'VARCHAR',
'constraint' => '15',
),
'db_name' => array(
'type' => 'VARCHAR',
'constraint' => '25',
),
'update_date' => array(
'type' => 'datetime',
'on update' => 'NOW()',
),
'upgrade' => array(
'type' => 'tinyint',
'constraint' => '1',
'default' => '0',
),
'status' => array(
'type' => 'tinyint',
'constraint' => '1',
'default' => '4',
),
);
$this->dbforge->add_field($fields);
$this->dbforge->add_field("subscription_date TIMESTAMP DEFAULT CURRENT_TIMESTAMP");
$this->dbforge->add_field("subscription_expire TIMESTAMP DEFAULT '0000-00-00 00:00:00'");
$this->dbforge->add_key('id', TRUE);
$this->dbforge->create_table('tms_profile');
}
Table is successfully created but on update attributes not exists on the field named update_date. i want to set on update atrributes on the field.
All you have to do is change type of update_date column like
....
'update_date' => array(
'type' => 'TIMESTAMP'
),
.....
Now it will work ON UPDATE with NOW()
use inline declaration, like here:
`update_stamp` timestamp NOT NULL DEFAULT CURRENT_TIMESTAMP ON UPDATE CURRENT_TIMESTAMP',

I am using db forge for database migration.add_foreign_key add keys from first created table to second one

I am using db forge for database migration in ci.When I add foreign key in first created table. It works but in second table foreign key from first table inherit so it create problem to create the sencond table. Here is my code
<?php if (!defined('BASEPATH')) exit('No direct script access allowed');
class Initial_schema {
function up()
{
$CI =& get_instance();
if($CI->migrate->verbose)
echo "Creating tables...";
// create table TblRowStatusEnum
if(! $CI->db->table_exists('TblRowStatusEnum')) {
$cols = array(
'id' => array('type' => 'INT', 'constraint' => 11, 'auto_increment' => TRUE,'null'=>FALSE),
'status' => array('type' => 'enum("Active","Inactive","Delete")', 'null' => FALSE),
'description' => array('type' => 'VARCHAR', 'constraint' => '200', 'null' => True),
'createdAt' => array('type' => 'datetime', 'null' => FALSE),
'updatedAt' => array('type' => 'datetime', 'null' => TRUE)
);
// Setup Keys
$CI->dbforge->add_key('id', TRUE);
$CI->dbforge->add_field($cols);
$CI->dbforge->create_table('TblRowStatusEnum', TRUE);
//insert data
/*$insert = array('status' => 'Active','description' =>'Active');
$CI->db->insert('TblRowStatusEnum', $insert);
$insert = array('status' => 'Inactive','description' =>'Inactive');
$CI->db->insert('TblRowStatusEnum', $insert);
$insert = array('status' => 'Delete','description' =>'Delete');
$CI->db->insert('TblRowStatusEnum', $insert);*/
}
// create table TblUser
if(! $CI->db->table_exists('TblUser')) {
$cols = array(
'id' => array('type' => 'INT', 'constraint' => 11,'auto_increment' => TRUE,'null'=>FALSE),
'facebookId' => array('type' => 'INT','constraint' => '11', 'null' => FALSE),
'firstName' => array('type' => 'VARCHAR','constraint' => '255', 'null' => FALSE),
'middleName' => array('type' => 'VARCHAR','constraint' => '255', 'null' => TRUE),
'lastName' => array('type' => 'VARCHAR','constraint' => '255', 'null' => FALSE),
'email' => array('type' => 'VARCHAR','constraint' => '255', 'null' => FALSE),
'address' => array('type' => 'TEXT'),
'dateOfBirth' => array('type' => 'DATE'),
'facebookAuthToken' => array('type' => 'TEXT', 'null' => FALSE ,'comment'=>"For storing auth token for offline access. If we don''t need offline access this column can be deleted"),
'profileImageUrl' => array('type' => 'TEXT','null' => FALSE),
'rowStatus' => array('type' => 'INT','constraint' => '11','null' => FALSE),
'createdAt' => array('type' => 'DATETIME', 'null' => FALSE),
'updatedAt' => array('type' => 'DATETIME', 'null' => TRUE)
);
// Setup Keys
$CI->dbforge->add_key('id', TRUE);
$CI->dbforge->add_key('rowStatus');
$CI->dbforge->add_field($cols);
//gives CONSTRAINT FOREIGN KEY `fk_testTable_testField` (`myField`)
// REFERENCES testTable(`testField`) ON DELETE CASCADE ON UPDATE CASCADE
$CI->dbforge->add_foreign_key(array('field' => 'rowStatus',
'foreign_table' => 'TblRowStatusEnum',
'foreign_field' => 'id'));
$CI->dbforge->create_table('TblUser', TRUE);
}
//TblSellingItem
if(! $CI->db->table_exists('TblSellingItem')) {
$cols = array(
'id' => array('type' => 'INT', 'constraint' => 11,'auto_increment' => TRUE,'null'=>FALSE),
'title' => array('type' => 'VARCHAR','constraint' => '255', 'null' => FALSE),
'description' => array('type' => 'TEXT'),
'price' => array('type' => 'FLOAT','null' => FALSE),
'postedBy' => array('type' => 'INT','constraint' => 11,'null' => FALSE),
'rowStatus' => array('type' => 'INT','constraint' => 11,'null' => FALSE),
'createdAt' => array('type' => 'datetime', 'null' => FALSE,'default'=>get_now()),
'updatedAt' => array('type' => 'datetime', 'null' => TRUE)
);
// Setup Keys
$CI->dbforge->add_key('id', TRUE);
$CI->dbforge->add_key('postedBy');
$CI->dbforge->add_key('rowStatus');
$CI->dbforge->add_field($cols);
$CI->dbforge->add_foreign_key(array('field' => 'rowStatus',
'foreign_table' => 'TblRowStatusEnum',
'foreign_field' => 'id'));
$CI->dbforge->add_foreign_key(array('field' => 'postedBy',
'foreign_table' => 'TblUser',
'foreign_field' => 'id'));
$CI->dbforge->create_table('TblSellingItem', TRUE);
}
//TblItemImage
if(! $CI->db->table_exists('TblItemImage')) {
$cols = array(
'id' => array('type' => 'INT', 'constraint' => 11, 'auto_increment' => TRUE,'null'=>FALSE),
'sellingItemId' => array('type' => 'INT','constraint' => '11', 'null' => FALSE),
'url' => array('type' => 'TEXT','null' => FALSE),
'imageOrder' => array('type' => 'INT','null' => FALSE),
'rowStatus' => array('type' => 'INT','constraint' => 11,'null' => FALSE),
'createdAt' => array('type' => 'datetime', 'null' => FALSE,'default'=>get_now()),
'updatedAt' => array('type' => 'datetime', 'null' => TRUE)
);
// Setup Keys
$status =array('field' => 'rowStatus',
'foreign_table' => 'TblRowStatusEnum',
'foreign_field' => 'id');
$posted_by =array('field' => 'sellingItemId',
'foreign_table' => 'TblSellingItem',
'foreign_field' => 'id');
$CI->dbforge->add_key('id', TRUE);
$CI->dbforge->add_key('sellingItemId');
$CI->dbforge->add_key('rowStatus');
$CI->dbforge->add_field($cols);
$CI->dbforge->add_foreign_key($status);
$CI->dbforge->add_foreign_key($posted_by);
$CI->dbforge->create_table('TblItemImage', TRUE);
}
//TblChatMessage
if(! $CI->db->table_exists('TblChatMessage')) {
$cols = array(
'id' => array('type' => 'INT', 'constraint' => 11, 'auto_increment' => TRUE,'null'=>FALSE),
'sellingItemId' => array('type' => 'INT','constraint' => '11', 'null' => FALSE),
'message' => array('type' => 'TEXT'),
'sender' => array('type' => 'INT','null' => FALSE),
'receiver' => array('type' => 'INT','null' => FALSE),
'sentTime' => array('type' => 'datetime', 'null' => FALSE),
'messageStatus' => array('type' => 'INT','constraint' => 11,'null' => FALSE),
'rowStatus' => array('type' => 'INT','constraint' => 11,'null' => FALSE),
'createdAt' => array('type' => 'datetime', 'null' => FALSE,'default'=>get_now()),
'updatedAt' => array('type' => 'datetime', 'null' => TRUE)
);
// Setup Keys
$CI->dbforge->add_key('id', TRUE);
$CI->dbforge->add_key('sellingItemId');
$CI->dbforge->add_key('sender');
$CI->dbforge->add_key('receiver');
$CI->dbforge->add_key('rowStatus');
$CI->dbforge->add_field($cols);
$CI->dbforge->add_foreign_key(array('field' => 'rowStatus',
'foreign_table' => 'TblRowStatusEnum',
'foreign_field' => 'id'));
$CI->dbforge->add_foreign_key(array('field' => 'sellingItemId',
'foreign_table' => 'TblSellingItem',
'foreign_field' => 'id'));
$CI->dbforge->add_foreign_key(array('field' => 'receiver',
'foreign_table' => 'TblUser',
'foreign_field' => 'id'));
$CI->dbforge->add_foreign_key(array('field' => 'sender',
'foreign_table' => 'TblUser',
'foreign_field' => 'id'));
$CI->dbforge->create_table('TblChatMessage', TRUE);
}
}
function down()
{
$CI =& get_instance();
if($CI->migrate->verbose)
echo "Dropping table accounts...";
$CI->dbforge->drop_table('TblRowStatusEnum');
}
}
?>
Error is like this
A Database Error Occurred
Error Number: 1072
Key column 'postedBy' doesn't exist in table
CREATE TABLE IF NOT EXISTS `TblItemImage` ( `id` INT(11) NOT NULL AUTO_INCREMENT,
`sellingItemId` INT(11) NOT NULL, `url` TEXT NOT NULL, `imageOrder` INT NOT NULL,
`rowStatus` INT(11) NOT NULL, `createdAt` datetime DEFAULT '2014-03-19 11:51:13' NOT NULL,
`updatedAt` datetime NULL, PRIMARY KEY `id` (`id`), FOREIGN KEY `rowStatus` (`rowStatus`)
REFERENCES `TblRowStatusEnum`(`id`), FOREIGN KEY `rowStatus` (`rowStatus`) REFERENCES
`TblRowStatusEnum`(`id`), FOREIGN KEY `postedBy` (`postedBy`) REFERENCES `TblUser`(`id`),
FOREIGN KEY `rowStatus` (`rowStatus`) REFERENCES `TblRowStatusEnum`(`id`), FOREIGN KEY
`sellingItemId` (`sellingItemId`) REFERENCES `TblSellingItem`(`id`), KEY `sellingItemId`
(`sellingItemId`), KEY `rowStatus` (`rowStatus`) ) DEFAULT CHARACTER SET utf8 COLLATE utf8_general_ci;
Filename: C:\xampp\htdocs\plunder_migration\system\database\DB_driver.php
Line Number: 330
here FOREIGN KEY postedBy is add automatically in table TblItemImage. what is wrong with my code? Thank You.
Could you make a test by changing the constraint postedBy by the following code and give us the result?
postedBy' => array('type' => 'INT','constraint' => 11,'null' => TRUE),

Categories