Lançado Adianti Framework 7.6!
Clique aqui para saber mais
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 ...
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

  1. <?php
  2. /**
  3.  * PreventivaFormView Registration
  4.  * @author  <your name here>
  5.  */
  6. class PreventivaFormView extends TPage
  7. {
  8.     protected $form// form
  9.     
  10.     use Adianti\Base\AdiantiStandardFormTrait// Standard form methods
  11.     
  12.     /**
  13.      * Class constructor
  14.      * Creates the page and the registration form
  15.      */
  16.     function __construct()
  17.     {
  18.         parent::__construct();
  19.         
  20.         $this->setDatabase('sample');              // defines the database
  21.         $this->setActiveRecord('Preventivas');     // defines the active record
  22.         
  23.         // creates the form
  24.         $this->form = new BootstrapFormBuilder('form_Preventivas');
  25.         $this->form->setFormTitle('Preventivas');
  26.         
  27.         // create the form fields
  28.         $id_preventiva = new THidden('id_preventiva');
  29.         $descricao = new TEntry('descricao');
  30.         // add the fields
  31.         $this->form->addFields( [ new TLabel('Id Preventiva') ], [ $id_preventiva ] );
  32.         $this->form->addFields( [ new TLabel('Descricao') ], [ $descricao ] );
  33.         // set sizes
  34.         $id_preventiva->setSize('100%');
  35.         $descricao->setSize('100%');
  36.         
  37.         if (!empty($id_preventiva))
  38.         {
  39.             $id_preventiva->setEditable(FALSE);
  40.         }
  41.         
  42.         /** samples
  43.          $fieldX->addValidation( 'Field X', new TRequiredValidator ); // add validation
  44.          $fieldX->setSize( '100%' ); // set size
  45.          **/
  46.          
  47.         // create the form actions
  48.         $btn $this->form->addAction(_t('Save'), new TAction([$this'onSave']), 'fa:floppy-o');
  49.         $btn->class 'btn btn-sm btn-primary';
  50.         $this->form->addAction(_t('New'),  new TAction([$this'onEdit']), 'fa:eraser red');
  51.         
  52.         // vertical box container
  53.         $container = new TVBox;
  54.         $container->style 'width: 90%';
  55.         // $container->add(new TXMLBreadCrumb('menu.xml', __CLASS__));
  56.         $container->add($this->form);
  57.         
  58.         parent::add($container);
  59.     }
  60. }
  61. Preventivas.class.php:
  1. <?php
  2. /**
  3.  * Customer Active Record
  4.  * @author  Raphael Mohandas
  5.  */
  6. class Preventivas extends TRecord
  7. {
  8.     const TABLENAME 'preventivas';
  9.     const PRIMARYKEY'id_preventiva';
  10.     const IDPOLICY =  'max'// {max, serial}
  11.     
  12.     public function __construct($id_preventiva NULL)
  13.     {
  14.         parent::__construct($id_preventiva);
  15.         parent::addAttribute('descricao');
  16.         
  17.         
  18.         
  19.        
  20.     }
  21. }
  22. ?>


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;

Curso completo Meu Negócio Pronto
Use para si, ou transforme em um negócio: Inclui aulas e códigos-fontes
Gestor de conteúdo (SITE) + Loja Virtual (E-Commerce) + Emissor de Notas para infoprodutos


Meu negócio pronto Quero me inscrever agora!

Comentários (3)


NR

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
RR

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.
NR

Nesse caso copie a função onSave pra dentro da sua classe e verifique o sql gerado:
  1. <?php
  2. TTransaction::setLogger(new TLoggerSTD); //isso vai exibir o sql em tela
  3. ?>