Asterisk 11 queue log to mysql - asterisk

How can i change default storage of queue log from /var/log/asterisk/queue_log file to asteriskcdrdb.queue_log table in MySQL in Asterisk 11?

You should have in /etc/asterisk/extconfig.conf:
[settings]
queue_log => mysql,dsn,tablename
and in /etc/asterisk/res_config_mysql.conf:
[dsn]
dbname = database_name
dbuser = database_user
dbpass = database_pass
dbcharset = utf8
requirements = warn
The schema for the table is:
CREATE TABLE `tablename` (
`id` bigint(255) unsigned NOT NULL AUTO_INCREMENT,
`time` varchar(26) NOT NULL DEFAULT '',
`callid` varchar(40) NOT NULL DEFAULT '',
`queuename` varchar(20) NOT NULL DEFAULT '',
`agent` varchar(20) NOT NULL DEFAULT '',
`event` varchar(20) NOT NULL DEFAULT '',
`data` varchar(100) NOT NULL DEFAULT '',
`data1` varchar(40) NOT NULL DEFAULT '',
`data2` varchar(40) NOT NULL DEFAULT '',
`data3` varchar(40) NOT NULL DEFAULT '',
`data4` varchar(40) NOT NULL DEFAULT '',
`data5` varchar(40) NOT NULL DEFAULT '',
`created` timestamp NOT NULL DEFAULT CURRENT_TIMESTAMP,
PRIMARY KEY (`id`),
KEY `queue` (`queuename`),
KEY `event` (`event`)
) DEFAULT CHARSET=utf8;

I suggest that you take a look at the following link:
http://www.voip-info.org/wiki/view/Asterisk+queue_log+on+MySQL
Bear in mind that most of these configurations are already well know, and will be documented on the www.voip-info.org wiki.

Related

MariaDB is throwing a syntax error when creating foreign key

CREATE DATABASE mylaboratory;
USE mylaboratory;
DROP TABLE IF EXISTS `Account`;
CREATE TABLE `Account` (
`Email` varchar(255) NOT NULL COMMENT '계정 이메일 (ID)',
`HashedPassword` longtext NOT NULL COMMENT '계정 암호화 된 비밀번호',
`FullName` varchar(255) NOT NULL COMMENT '계정 성명',
`AvatarImagePath` varchar(255) NOT NULL DEFAULT '/upload/Management/Profile/default-avatar.jpg' COMMENT '계정 아바타 이미지 경로',
`Role` varchar(255) NOT NULL DEFAULT 'User' COMMENT '계정 역할 (Admin 또는 User)',
`Locked` tinyint(1) NOT NULL COMMENT '계정 잠금',
`LoginAttempt` int(11) NOT NULL COMMENT '로그인 시도 횟수',
`EmailConfirmed` tinyint(1) NOT NULL COMMENT '이메일 확인 여부',
`AgreedServiceTerms` tinyint(1) NOT NULL COMMENT '약관 동의 여부',
`RegistrationToken` longtext DEFAULT NULL COMMENT '회원가입 인증 토큰',
`ResetPasswordToken` longtext DEFAULT NULL COMMENT '비밀번호 찾기 인증 토큰',
`Created` datetime(6) NOT NULL DEFAULT '1900-01-01 00:00:00.000000' COMMENT '계정 생성일',
`Updated` datetime(6) NOT NULL DEFAULT '1900-01-01 00:00:00.000000' COMMENT '계정 업데이트일',
`Message` longtext DEFAULT NULL COMMENT '계정 상태 메시지',
`Deleted` tinyint(1) NOT NULL COMMENT '계정 삭제 여부',
PRIMARY KEY (`Email`),
CONSTRAINT `Accounts_check` CHECK (`Role` = 'Admin' or `Role` = 'User')
) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COMMENT 'MyLaboratory.Site 계정';
CREATE TABLE mylaboratory.Asset (
Email varchar(255) NOT NULL COMMENT '계정 이메일 (ID)',
ProductName varchar(255) NOT NULL COMMENT '상품명 (은행 계좌명, 증권 계좌명, 현금 등)',
item varchar(255) NOT NULL COMMENT '항목 (자유입출금 자산, 신탁 자산, 현금 자산, 저축성 자산, 투자성 자산, 부동산, 동산, 기타 실물 자산, 보험 자산)',
Amount BIGINT(255) NOT NULL COMMENT '금액',
MonetaryUnit varchar(255) NOT NULL COMMENT '화폐 단위 (KRW, USD, ETC)',
Created DATETIME(6) NOT NULL COMMENT '생성일',
Updated DATETIME(6) NOT NULL COMMENT '업데이트일',
Note varchar(255) NULL COMMENT '비고',
Reserved0 varchar(100) NULL,
Reserved1 varchar(100) NULL,
Reserved2 varchar(100) NULL,
Reserved3 varchar(100) NULL,
Reserved4 varchar(100) NULL,
PRIMARY KEY (Email, ProductName),
KEY Asset_FK (Email),
CONSTRAINT Asset_FK FOREIGN KEY (Email) REFERENCES mylaboratory.Account(Email)
)
ENGINE=InnoDB
DEFAULT CHARSET=utf8
COLLATE=utf8_general_ci
COMMENT='계정 자산';
Error:
Error occurred during SQL query execution
SQL Error [1005] [HY000]: (conn=61) Can't create table mylaboratory.asset (errno: 150 "Foreign key constraint is incorrectly formed")
I can't figure it out what is wrong in foreign key syntax.
MariaDB 10.2.38 version.
You can not use two different character sets with a foreign key, they have to be the same or at least compatible
CREATE TABLE Asset (
Email varchar(255) NOT NULL COMMENT '계정 이메일 (ID)',
ProductName varchar(255) NOT NULL COMMENT '상품명 (은행 계좌명, 증권 계좌명, 현금 등)',
item varchar(255) NOT NULL COMMENT '항목 (자유입출금 자산, 신탁 자산, 현금 자산, 저축성 자산, 투자성 자산, 부동산, 동산, 기타 실물 자산, 보험 자산)',
Amount BIGINT(255) NOT NULL COMMENT '금액',
MonetaryUnit varchar(255) NOT NULL COMMENT '화폐 단위 (KRW, USD, ETC)',
Created DATETIME(6) NOT NULL COMMENT '생성일',
Updated DATETIME(6) NOT NULL COMMENT '업데이트일',
Note varchar(255) NULL COMMENT '비고',
Reserved0 varchar(100) NULL,
Reserved1 varchar(100) NULL,
Reserved2 varchar(100) NULL,
Reserved3 varchar(100) NULL,
Reserved4 varchar(100) NULL,
PRIMARY KEY (Email, ProductName),
KEY Asset_FK (Email),
CONSTRAINT Asset_FK FOREIGN KEY (Email) REFERENCES Account(Email)
)
ENGINE=InnoDB
DEFAULT CHARSET=utf8mb4

Error in Insert Value "answer" in CDR Database Asterisk

This error occurs to me sometimes when the call is hung up. The rest is saved normally. I expose a bad record and a good one
[Dec 6 19:47:19] ERROR[31348][C-00000045]: cdr_mysql.c:349 mysql_log:
Failed to insert into database: (1292) Incorrect datetime value:
‘SIP/sip_lbascunan/961258985,160,wWTt’ for column ‘answer’ at row 1
Good Row
‘1575675020.46’, ‘1575675020.46’, ‘“343591171” <343591171>’,
‘343591171’, ‘101961258985’, ‘engine’, ‘SIP/asterisk-63-0000002e’,
‘SIP/opsmovil-0000002f’, ‘Hangup’, ‘’, ‘2019-12-06 20:30:20’, NULL,
‘2019-12-06 20:30:20’, ‘0’, ‘0’, ‘NO ANSWER’, ‘3’, ‘’, ‘’, ‘55’, ‘’
Bad Row
‘1575674496.30’, ‘1575674496.30’, ‘“SISTEMAS” <1084>’, ‘1084’,
‘90962108827’, ‘lbascunan’, ‘SIP/1084-0000001e’,
‘SIP/sip_lbascunan-0000001f’, ‘Dial’,
‘SIP/sip_lbascunan/962108827,160,wWTt’, ‘2019-12-06 20:21:36’,
‘SIP/sip_lbascunan/962108827,160,wWTt’, ‘2019-12-06 20:22:00’, ‘24’,
‘0’, ‘NO ANSWER’, ‘3’, ‘’, ‘’, ‘35’, ‘’
I had to change the Answer field from Varchar to Datetime so that I could save.
This is my Table CDR
CREATE TABLE `cdr` (
`uniqueid` varchar(32) NOT NULL DEFAULT '',
`linkedid` varchar(32) NOT NULL DEFAULT '',
`clid` varchar(80) NOT NULL DEFAULT '',
`src` varchar(80) NOT NULL DEFAULT '',
`dst` varchar(80) NOT NULL DEFAULT '',
`dcontext` varchar(80) NOT NULL DEFAULT '',
`channel` varchar(80) NOT NULL DEFAULT '',
`dstchannel` varchar(80) NOT NULL DEFAULT '',
`lastapp` varchar(80) NOT NULL DEFAULT '',
`lastdata` varchar(80) NOT NULL DEFAULT '',
`start` datetime NOT NULL,
`answer` datetime NOT NULL,
`end` datetime NOT NULL,
`duration` int(11) NOT NULL DEFAULT '0',
`billsec` int(11) NOT NULL DEFAULT '0',
`disposition` varchar(45) NOT NULL DEFAULT '',
`amaflags` int(11) NOT NULL DEFAULT '0',
`accountcode` varchar(20) NOT NULL DEFAULT '',
`userfield` varchar(255) NOT NULL DEFAULT '',
`sequence` varchar(32) NOT NULL DEFAULT '',
`peeraccount` varchar(32) NOT NULL DEFAULT '',
PRIMARY KEY (`uniqueid`),
KEY `start` (`start`),
KEY `dst` (`dst`),
KEY `accountcode` (`accountcode`)
) ENGINE=InnoDB DEFAULT CHARSET=utf8;
Just incorrect quatation.
Check special symbols in callerid(name).
Anyway it is nothing to answer. Just bad system design and no check for sql injection.

Cannot convert Query with Subquery to Symfony Doctrine QueryBuilder

I have a query that does what is required
SELECT v.* FROM vehicle v
WHERE v.company_id = 2 AND v.id NOT IN
(
SELECT h.vehicle_id
FROM hire h
WHERE
h.start_date is not null and h.end_date is null
)
So now I am trying to code this query in Symfony/Doctrine
I have this
$qb = $this->_em->createQueryBuilder();
$subq = $this->_em->createQueryBuilder();
$subq ->select('h.vehicle')
->from('AppBundle\Entity\Hire', 'h')
->andWhere('h.startDate is not null and h.endDate is null');
$qb->select('v')
->from('AppBundle\Entity\Vehicle', 'v')
->where($qb->expr()->notIn('v.id',$subq->getDQL()))
->andWhere('v.company = :company')
->setParameter('company', $company)
->orderBy('v.registrationNumber', 'ASC')
;
$t = $qb->getDQL();
return $qb;
As you see I tried dumping the DQL to see if that gave me any clues and here is is
SELECT v
FROM AppBundle\Entity\Vehicle v
WHERE (v.id NOT IN(SELECT h.vehicle FROM AppBundle\Entity\Hire h WHERE h.startDate is not null and h.endDate is null))
AND v.company = :company
ORDER BY v.registrationNumber ASC
I tried converting this back to simple SQL i.e. removing the AppBundle stuff and converting the column names back to actual column name and it runs and get the right result.
But I am getting this error
Doctrine\ORM\Query\QueryException:
[Semantical Error] line 0, col 69 near 'vehicle FROM': Error: Invalid PathExpression. Must be a StateFieldPathExpression.
at vendor\doctrine\orm\lib\Doctrine\ORM\Query\QueryException.php:63
at Doctrine\ORM\Query\QueryException::semanticalError('line 0, col 69 near \'vehicle FROM\': Error: Invalid PathExpression. Must be a StateFieldPathExpression.', object(QueryException))
The 2 tables involved are
CREATE TABLE `hire` (
`id` int(11) NOT NULL AUTO_INCREMENT,
`company_id` int(11) DEFAULT NULL,
`driver_id` int(11) DEFAULT NULL,
`vehicle_id` int(11) DEFAULT NULL,
`corporate_hire` tinyint(1) DEFAULT NULL,
`end_date` datetime DEFAULT NULL,
`end_miles` decimal(10,1) DEFAULT NULL,
`start_date` datetime DEFAULT NULL,
`start_miles` decimal(10,1) DEFAULT NULL,
`created_by` varchar(255) COLLATE utf8_unicode_ci DEFAULT NULL,
`updated_by` varchar(255) COLLATE utf8_unicode_ci DEFAULT NULL,
`deleted_by` varchar(255) COLLATE utf8_unicode_ci DEFAULT NULL,
`deleted_at` datetime DEFAULT NULL,
`created_at` datetime DEFAULT NULL,
`updated_at` datetime DEFAULT NULL,
PRIMARY KEY (`id`),
KEY `IDX_B8017EFC979B1AD6` (`company_id`),
KEY `IDX_B8017EFCC3423909` (`driver_id`),
KEY `IDX_B8017EFC545317D1` (`vehicle_id`),
CONSTRAINT `FK_B8017EFC545317D1` FOREIGN KEY (`vehicle_id`) REFERENCES `vehicle` (`id`) ON DELETE SET NULL,
CONSTRAINT `FK_B8017EFC979B1AD6` FOREIGN KEY (`company_id`) REFERENCES `company` (`id`) ON DELETE SET NULL,
CONSTRAINT `FK_B8017EFCC3423909` FOREIGN KEY (`driver_id`) REFERENCES `driver` (`id`) ON DELETE SET NULL
) ENGINE=InnoDB AUTO_INCREMENT=29 DEFAULT CHARSET=utf8 COLLATE=utf8_unicode_ci;
and
CREATE TABLE `vehicle` (
`id` int(11) NOT NULL AUTO_INCREMENT,
`company_id` int(11) DEFAULT NULL,
`storage_id` int(11) DEFAULT NULL,
`created_by` varchar(255) COLLATE utf8_unicode_ci DEFAULT NULL,
`updated_by` varchar(255) COLLATE utf8_unicode_ci DEFAULT NULL,
`deleted_by` varchar(255) COLLATE utf8_unicode_ci DEFAULT NULL,
`deleted_at` datetime DEFAULT NULL,
`created_at` datetime DEFAULT NULL,
`updated_at` datetime DEFAULT NULL,
`date_of_manufacture` datetime DEFAULT NULL,
`engine_size` int(11) DEFAULT NULL,
`make` varchar(50) COLLATE utf8_unicode_ci DEFAULT NULL,
`model` varchar(50) COLLATE utf8_unicode_ci DEFAULT NULL,
`registration_number` varchar(10) COLLATE utf8_unicode_ci NOT NULL,
`vin` varchar(20) COLLATE utf8_unicode_ci DEFAULT NULL,
PRIMARY KEY (`id`),
KEY `IDX_1B80E486979B1AD6` (`company_id`),
KEY `IDX_1B80E4865CC5DB90` (`storage_id`),
CONSTRAINT `FK_1B80E4865CC5DB90` FOREIGN KEY (`storage_id`) REFERENCES `storage` (`id`) ON DELETE SET NULL,
CONSTRAINT `FK_1B80E486979B1AD6` FOREIGN KEY (`company_id`) REFERENCES `company` (`id`) ON DELETE SET NULL
) ENGINE=InnoDB AUTO_INCREMENT=25 DEFAULT CHARSET=utf8 COLLATE=utf8_unicode_ci;
I am not sure what an Invalid Path Expression should be making me look for as an actual error.
What's working for us is (adapted to your example, so not tested):
$subQuery->select('IDENTITY(h.vehicle)');
$subQuery->from('AppBundle\Entity\Hire', 'h');
$dqlString = $subQuery->getQuery()->getDQL();
$query->andWhere('v.id' 'NOT IN (' . $dqlString . ')');
The only two differences that I see are:
subQuery returns IDENTITY() of h.vehicle, so only the 'identifier' (which is id in most cases)
our andWhere condition in main query is created manually - but your expression builder should work the same way.
So my assumption ist that your $subq ->select('h.vehicle') doesn't return ids which can be used in the NOT IN condition of your main query, which might be proven by your resolved DQL SELECT v : this will return all fields, but you'd required v.id only.

Wordpress dbdelta a semicolon

Ok i have query something like this
$drzava ="CREATE TABLE IF NOT EXISTS`wp_drzava` (
`ID` int(11) NOT NULL AUTO_INCREMENT,
`Kod` varchar(2) NOT NULL,
`Naziv` varchar(100) NOT NULL,
`NazivSrb` varchar(100) NOT NULL,
`NazivSrbGenetiv` varchar(100) NOT NULL,
`jePrevedeno` tinyint(4) DEFAULT '0',
`jeDrzava` tinyint(1) DEFAULT '1',
`PhoneCode` varchar(10) DEFAULT NULL,
`NazivRo` varchar(255) DEFAULT NULL,
PRIMARY KEY (`ID`)
) ENGINE=MyISAM AUTO_INCREMENT=304 DEFAULT CHARSET=utf8;
INSERT INTO wp_drzava VALUES ('249', 'RO', 'Romania', 'Rumunija', 'Rumunije', null, '1', '+40', 'România ')";
Problem seems to be in România record, so i get not record inserted. I try dbDelta() function and also $wpdb->query() but i get no result. Can someone help me to resolve this problem
INSERT INTO wp_drzava(ID, Kod, Naziv, NazivSrb, NazivSrbGenetiv, jePrevedeno, jeDrzava, PhoneCode, NazivRo) VALUES ('249', 'RO', 'Romania', 'Rumunija', 'Rumunije', null, '1', '+40', 'România ')";
Answer is
$drzava = array();
$drzava[] ="CREATE TABLE IF NOT EXISTS`wp_drzava` (
`ID` int(11) NOT NULL AUTO_INCREMENT,
`Kod` varchar(2) NOT NULL,
`Naziv` varchar(100) NOT NULL,
`NazivSrb` varchar(100) NOT NULL,
`NazivSrbGenetiv` varchar(100) NOT NULL,
`jePrevedeno` tinyint(4) DEFAULT '0',
`jeDrzava` tinyint(1) DEFAULT '1',
`PhoneCode` varchar(10) DEFAULT NULL,
`NazivRo` varchar(255) DEFAULT NULL,
PRIMARY KEY (`ID`)
) ENGINE=MyISAM AUTO_INCREMENT=304 DEFAULT CHARSET=utf8;"
$drzava[] ="INSERT INTO wp_drzava VALUES ('249', 'RO', 'Romania', 'Rumunija', 'Rumunije', null, '1', '+40', 'România ')";
So we must insert array into dbDelta function!

Warning: spl_object_hash() expects parameter 1 to be object

Warning: spl_object_hash() expects parameter 1 to be object, string given in
/var/www/sitetwo/vendor/doctrine/orm/lib/Doctrine/ORM/UnitOfWork.php line 1367
I created MainBlogBundle with Category.php and Product.php using yml mapping annotation via php app/console commands. After using CRUD actions for add/edit/delete/show actions I tried to add a category and after submitting Add category form I get the
Warning: spl_object_hash() expects parameter 1 to be object, string given in
/var/www/sitetwo/vendor/doctrine/orm/lib/Doctrine/ORM/UnitOfWork.php line 1367
I posted my sample code on github and below is the script of database.
git#github.com:veerpartap/ProblemSymfony.git
/****************************************************************************/
-- phpMyAdmin SQL Dump
-- version 3.4.10.1deb1
-- http://www.phpmyadmin.net
--
-- Host: localhost
-- Generation Time: Oct 26, 2013 at 01:56 PM
-- Server version: 5.5.32
-- PHP Version: 5.5.3-1+debphp.org~precise+2
SET SQL_MODE="NO_AUTO_VALUE_ON_ZERO";
SET time_zone = "+00:00";
--
-- Database: `sitetwo`
--
-- --------------------------------------------------------
--
-- Table structure for table `category`
--
CREATE TABLE IF NOT EXISTS `category` (
`id` int(11) NOT NULL AUTO_INCREMENT,
`name` varchar(255) COLLATE utf8_unicode_ci NOT NULL,
PRIMARY KEY (`id`)
) ENGINE=InnoDB DEFAULT CHARSET=utf8 COLLATE=utf8_unicode_ci AUTO_INCREMENT=1 ;
-- --------------------------------------------------------
--
-- Table structure for table `Company`
--
CREATE TABLE IF NOT EXISTS `Company` (
`id` int(11) NOT NULL AUTO_INCREMENT,
`company_name` varchar(255) COLLATE utf8_unicode_ci NOT NULL,
`address` varchar(255) COLLATE utf8_unicode_ci NOT NULL,
`owner_name` varchar(150) COLLATE utf8_unicode_ci NOT NULL,
`status` tinyint(1) NOT NULL,
`created` datetime NOT NULL,
PRIMARY KEY (`id`)
) ENGINE=InnoDB DEFAULT CHARSET=utf8 COLLATE=utf8_unicode_ci AUTO_INCREMENT=3 ;
--
-- Dumping data for table `Company`
--
INSERT INTO `Company` (`id`, `company_name`, `address`, `owner_name`, `status`, `created`) VALUES
(1, 'My First Company', 'Street 5A Sector 85 Chandigarh 1665588', 'Mr. Prateek Kumar', 1, '2013-09-06 00:00:00'),
(2, 'My Second Private Company', 'Street 34N Sector 89, Chandigarh 165898', 'Mr. Saurabh Shuja', 1, '2013-09-07 00:00:00');
-- --------------------------------------------------------
--
-- Table structure for table `Post`
--
CREATE TABLE IF NOT EXISTS `Post` (
`id` int(11) NOT NULL AUTO_INCREMENT,
`title` varchar(250) COLLATE utf8_unicode_ci NOT NULL,
`body` longtext COLLATE utf8_unicode_ci NOT NULL,
`published` datetime NOT NULL,
PRIMARY KEY (`id`)
) ENGINE=InnoDB DEFAULT CHARSET=utf8 COLLATE=utf8_unicode_ci AUTO_INCREMENT=1 ;
-- --------------------------------------------------------
--
-- Table structure for table `posts`
--
CREATE TABLE IF NOT EXISTS `posts` (
`id` int(11) NOT NULL AUTO_INCREMENT,
`title` varchar(250) COLLATE utf8_unicode_ci NOT NULL,
`body` longtext COLLATE utf8_unicode_ci NOT NULL,
`published` datetime NOT NULL,
PRIMARY KEY (`id`)
) ENGINE=InnoDB DEFAULT CHARSET=utf8 COLLATE=utf8_unicode_ci AUTO_INCREMENT=1 ;
-- --------------------------------------------------------
--
-- Table structure for table `products`
--
CREATE TABLE IF NOT EXISTS `products` (
`id` int(11) NOT NULL AUTO_INCREMENT,
`category_id` int(11) DEFAULT NULL,
`name` varchar(100) COLLATE utf8_unicode_ci NOT NULL,
`price` decimal(10,0) NOT NULL,
`description` longtext COLLATE utf8_unicode_ci NOT NULL,
PRIMARY KEY (`id`),
KEY `IDX_B3BA5A5A12469DE2` (`category_id`)
) ENGINE=InnoDB DEFAULT CHARSET=utf8 COLLATE=utf8_unicode_ci AUTO_INCREMENT=1 ;
-- --------------------------------------------------------
--
-- Table structure for table `User`
--
CREATE TABLE IF NOT EXISTS `User` (
`id` int(11) NOT NULL AUTO_INCREMENT,
`first_name` varchar(150) NOT NULL,
`last_name` varchar(150) NOT NULL,
`sex` tinyint(1) DEFAULT NULL,
`date_of_birth` datetime DEFAULT NULL,
`education` varchar(10) NOT NULL,
`mobile` varchar(10) NOT NULL,
`email` varchar(100) NOT NULL,
`address` varchar(200) NOT NULL,
`status` tinyint(1) DEFAULT NULL,
PRIMARY KEY (`id`)
) ENGINE=InnoDB DEFAULT CHARSET=latin1 AUTO_INCREMENT=3 ;
--
-- Dumping data for table `User`
--
INSERT INTO `User` (`id`, `first_name`, `last_name`, `sex`, `date_of_birth`, `education`, `mobile`, `email`, `address`, `status`) VALUES
(1, 'Veerpartap', 'Singh', 1, '2008-11-24 00:00:00', 'MCA', '71505897', 'metveerpartapsingh#gmail.com', 'hl 99 phase 2 sas nagar mohali', 1),
(2, 'Vicky', 'Sharma', 1, '2008-05-09 00:00:00', 'MCA', '88754257', 'vicky.sharma#gmail.com', 'Village Burari, Jila Nawanshar', 1);
--
-- Constraints for dumped tables
--
--
-- Constraints for table `products`
--
ALTER TABLE `products`
ADD CONSTRAINT `FK_B3BA5A5A12469DE2` FOREIGN KEY (`category_id`) REFERENCES `category` (`id`);
/****************************************************************************/
As stated in the above comment, the issue was about that I am not including the Arrarycollection namespace in the controller file. But after including the namespace I get another error while adding new products.
Below is the error message :
"__toString()" method was not foudn on the object of type Main\BlogBundle\Enity\Category to the choice field.
For this error, We need to add a __toString() method to your Category entity. For example:
public function __toString() { return $this->name; }
The PHP magic-method __toString() is used to present a textual representation of the object. In this case, the Category name will be used when selecting a Category in a Form of a related entity.
if you getthe __toString() error in a class XxxxxType extends AbstractType
you can add the fiel definition in the builder, like this. No need to modify your entity.
$builder
->add('enquete','entity',array('class' => 'AdequatSipBundle:Enquete',
'property' => 'Id', 'read_only'=>true))
->add('produit','entity',array('class' => 'AdequatSipBundle:Produit',
'property' => 'Name', 'read_only'=>true))

Resources