RR
doesn't have a default value
Galera estou precisando de um help seguinte quando vou salvar so fica dando esta msg " SQLSTATE[HY000]: General error: 1364 Field 'descricao' doesn't have a default value " ja revisei o código todo segue abaixo:
PreventivaFormView.php
SQL:
CREATE TABLE sistema.preventivas (
id_preventiva int(11) NOT NULL AUTO_INCREMENT,
descricao varchar(150) CHARACTER SET utf8 COLLATE utf8_general_ci DEFAULT NULL,
PRIMARY KEY (id_preventiva)
)
ENGINE = INNODB
AUTO_INCREMENT = 17
AVG_ROW_LENGTH = 16384
CHARACTER SET latin1
COLLATE latin1_swedish_ci
ROW_FORMAT = DYNAMIC;
PreventivaFormView.php
- <?php
- /**
- * PreventivaFormView Registration
- * @author <your name here>
- */
- class PreventivaFormView extends TPage
- {
- protected $form; // form
- use Adianti\Base\AdiantiStandardFormTrait; // Standard form methods
- /**
- * Class constructor
- * Creates the page and the registration form
- */
- function __construct()
- {
- parent::__construct();
- $this->setDatabase('sample'); // defines the database
- $this->setActiveRecord('Preventivas'); // defines the active record
- // creates the form
- $this->form = new BootstrapFormBuilder('form_Preventivas');
- $this->form->setFormTitle('Preventivas');
- // create the form fields
- $id_preventiva = new THidden('id_preventiva');
- $descricao = new TEntry('descricao');
- // add the fields
- $this->form->addFields( [ new TLabel('Id Preventiva') ], [ $id_preventiva ] );
- $this->form->addFields( [ new TLabel('Descricao') ], [ $descricao ] );
- // set sizes
- $id_preventiva->setSize('100%');
- $descricao->setSize('100%');
- if (!empty($id_preventiva))
- {
- $id_preventiva->setEditable(FALSE);
- }
- /** samples
- $fieldX->addValidation( 'Field X', new TRequiredValidator ); // add validation
- $fieldX->setSize( '100%' ); // set size
- **/
- // create the form actions
- $btn = $this->form->addAction(_t('Save'), new TAction([$this, 'onSave']), 'fa:floppy-o');
- $btn->class = 'btn btn-sm btn-primary';
- $this->form->addAction(_t('New'), new TAction([$this, 'onEdit']), 'fa:eraser red');
- // vertical box container
- $container = new TVBox;
- $container->style = 'width: 90%';
- // $container->add(new TXMLBreadCrumb('menu.xml', __CLASS__));
- $container->add($this->form);
- parent::add($container);
- }
- }
- Preventivas.class.php:
- <?php
- /**
- * Customer Active Record
- * @author Raphael Mohandas
- */
- class Preventivas extends TRecord
- {
- const TABLENAME = 'preventivas';
- const PRIMARYKEY= 'id_preventiva';
- const IDPOLICY = 'max'; // {max, serial}
- public function __construct($id_preventiva = NULL)
- {
- parent::__construct($id_preventiva);
- parent::addAttribute('descricao');
- }
- }
- ?>
SQL:
CREATE TABLE sistema.preventivas (
id_preventiva int(11) NOT NULL AUTO_INCREMENT,
descricao varchar(150) CHARACTER SET utf8 COLLATE utf8_general_ci DEFAULT NULL,
PRIMARY KEY (id_preventiva)
)
ENGINE = INNODB
AUTO_INCREMENT = 17
AVG_ROW_LENGTH = 16384
CHARACTER SET latin1
COLLATE latin1_swedish_ci
ROW_FORMAT = DYNAMIC;
Essa mensagem ocorre quando se tenta realizar um insert/update e um campo not null não é preenchido. Tem certeza que o model está apontando para a tabela correta? Pois no sql o nome está "sistema.preventivas" e no model está somente "preventivas"
Se isso estiver certo, tente habilitar os logs de sql para analisar
Não isso faz parte do sistema que faço conexão sql com o banco ele demonstra desta forma mesmo sistema.preventivas sistema e meu bd preventiva e a tabela.
Nesse caso copie a função onSave pra dentro da sua classe e verifique o sql gerado: